The official website for the New Rustacean podcast
OTHER License
Bot releases are hidden (Show)
Option::copied
, and the future of async/await syntax!Thanks to Parity for sponsoring the show and hiring Rust developers!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 5 years ago
Thanks to Parity for sponsoring the show and hiring Rust developers!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 5 years ago
It's impossible to make the declarations below follow the order I talked through them on the recording without also making them horrible to read, so just use this outline instead:
add_in_rust
Point
union
OpaquePoint
Thanks to Parity for sponsoring the show and hiring Rust developers!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 5 years ago
pub(<restricted>)
as API design tools.The easiest and most effective way to understand the example in this case
will simply be to look directly at the source code. You can read
the docs for each of the nested modules, but you'll be doing a lot of
navigating around for that.
Also, I am using Cargo’s --document-private-items
flag, so that you can
see all the items in all the modules, even those which are not public,
but note that usually you would not see docs for those!
Thanks to Manning for sponsoring the show and giving all of you a 40%-off
discount on their whole store (but especially their WebAssembly in
Action MEAP) at deals.manning.com/new-rustacean!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 5 years ago
The code samples here directly match the things I described in the show, so you will likely want to look at add
and ffi::add
, then Point
, translate
, and ffi::translate
in that order.
Other helpful Rust FFI discussions:
Thanks to Manning for sponsoring the show and giving all of you a 40%-off discount on their whole store (but especially Carol Nichols' and Jake Goulding's Rust in Motion video content and the Rust in Action MEAP!) at deals.manning.com/new-rustacean
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 5 years ago
Thanks to Parity for sponsoring the show and hiring Rust developers!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 5 years ago
const fn
, some Pin
, and alternative Cargo registries!Thanks to Parity for sponsoring the show and hiring Rust developers!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 5 years ago
Thanks to Parity for sponsoring the show and hiring Rust developers!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 5 years ago
Iterator
sourceThanks to Manning for sponsoring the show and giving all of you a 40%-off
discount on their whole store (but especially Carol Nichols' and Jake
Goulding's Rust in Motion video content and the Rust in Action MEAP!) at
deals.manning.com/new-rustacean
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 5 years ago
dbg!
, unified paths, more places you can use Self
, and aconst fn
stabilizations—plus some neat community highlights!Thanks to Parity for sponsoring the show again. Go check out their Rust
jobs!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho almost 6 years ago
Thanks to Parity for sponsoring the show again. Go check out their Rust
jobs!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho almost 6 years ago
const fn
(allconst fn
in the reference and “const contexts”
Thanks to Parity for sponsoring the show again. Go check out their Rust
jobs!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho almost 6 years ago
Things we mentioned on the show:
Thanks to Manning for sponsoring this episode; don’t forget to grab some of their content at 40% off using the code podnewrust18
!
Thanks to Parity for sponsoring the show again. Go check out their Rust jobs!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho almost 6 years ago
unsafe
Rust and Rust's idea of safety.A quick correction: on the show I said that a trait needed to be unsafe when it had an unsafe fn
method. This isn't correct: safe traits can have unsafe methods, and unsafe traits can exist without any methods at all (as implied by my reference to Send
and Sync
). You can see this in practice in the following example, which compiles just fine!
trait ASafeTrait {
unsafe fn unsafe_method() {}
}
unsafe AnUnsafeTrait {}
The idea of an unsafe
trait is that it has some conditions which you must uphold to safely implement it – again, just as with Send
and Sync
. In the case of most traits, this will be because some trait method has invariants it needs to hold else it would cause undefined behavior. For another example of this, see the (unstable as of the time of recording) trait std::iter::TrustedLen
.
Thanks to Rust language team member @centril for noting this to me after listening when I was recording the show live!
unsafe
let mut f = String::from("foo");
unsafe {
let borrowed = &mut f;
// This would be unsafe and throw an error (before Rust 2018):
// let borrow_again = &f;
println!("{}", borrowed);
// This would be unsafe and throw an error:
// println!("{}", borrow_again);
}
let f = Box::new(12);
let mut g = Box::into_raw(f);
g = &mut (g + 10);
Thanks to Parity for sponsoring the show again. Go check out their Rust
jobs!
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho almost 6 years ago
Thanks to Manning for sponsoring the show and giving all of you a 40%-off discount on their whole store (but especially Carol Nichols' and Jake Goulding's Rust in Motion video content and the Rust in Action MEAP!) at deals.manning.com/new-rustacean
[Joar Wandborg]: Joar Wandborg
[Jonathan Knapp]: https://www.coffeeandcode.com/
[John Rudnick]: http://www.cindur.com/
[Luiz Irber]: http://luizirber.org/
[Martin Heuschober]: https://github.com/epsilonhalbe
[Max Jacobson]: https://twitter.com/maxjacobson
[Messense Lv]: https://github.com/messense
[Michael Mc Donnell]: https://www.linkedin.com/in/michaelmcdonnell/
[Nathan Sculli]: http://influential.co/
[Nick Coish]: http://github.com/ncoish
[Nick Stevens]: https://github.com/nastevens
[Nicolas Pochet]: https://github.com/n-pochet
[Oluseyi Sonaiya]: http://oluseyi.info/
[Pascal]: https://pascalhertleif.de/
[Patrick O'Doherty]: https://twitter.com/patrickod
[Philipp Keller]: https://twitter.com/hansapla
[Ramon Buckland]: http://www.inosion.com
[Ryan Blecher]: http://notryanb.github.io/
[Ryan Osial]: https://github.com/osialr
[Sebastián Ramírez Magrí]: https://www.twitter.com/sebasmagri
[Simon Dickson]: https://www.simonhdickson.com/
[Stuart Hinson]: http://stuarth.github.io/
[William Roe]: http://willroe.me
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 6 years ago
Traits Deep Dive, Part 3
impl trait
, dyn trait
, and object safety!Sponsored by Parity Technologies! Parity is hiring Rust developers so if you're interested, you should check out their job listings!
You can see all of the pieces of the final example described in the show here (and the module has the required definitions for Point
).
let points = vec![
Point { x: 1.0, y: 2.0 },
Point { x: 12.0, y: 4.3 },
Point { x: -5.4, y: 18.7 },
];
let origin = Point::default();
// This is the version we start with. It works fine, but it's not elegant.
let distances_inline: Vec<f32> = points
.iter()
.map(|point| {
let change = point - &origin;
(change.x.powi(2) + change.y.powi(2)).sqrt()
})
.collect();
// This version is *much* cleaner!
let distances_impl: Vec<f32> = points.iter().map(distance_from_impl(&origin)).collect();
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 6 years ago
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 6 years ago
Traits—
Also of interest: specialization:
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 6 years ago
Rust 1.24
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)
Published by chriskrycho over 6 years ago
(Thanks to the couple people donating who opted out of the reward tier, as
well. You know who you are!)