Sveriges mest populära poddar
New Rustacean

e025: Traits Deep Dive, Part III

21 min5 juli 2018

Closure traits, `impl trait`, `dyn trait`, and object safety!

Show Notes

Sponsored by Parity Technologies! Parity is hiring Rust developers so if you’re interested, you should check out their job listings!

Links Example

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 = 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 = points.iter().map(distance_from_impl(&origin)).collect(); Sponsors

(Thanks to the couple people donating who opted out of the reward tier, as well. You know who you are!)

Become a sponsor Contact

New Rustacean med Chris Krycho finns tillgänglig på flera plattformar. Informationen på denna sida kommer från offentliga podd-flöden.