Closure traits, `impl trait`, `dyn trait`, and object safety!
\nShow Notes\nSponsored by Parity Technologies! Parity is hiring Rust developers so if you\u2019re interested, you should check out their job listings!
\nLinks\nYou 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![\n Point { x: 1.0, y: 2.0 },\n Point { x: 12.0, y: 4.3 },\n Point { x: -5.4, y: 18.7 },\n];\n\nlet origin = Point::default();\n\n// This is the version we start with. It works fine, but it's not elegant.\nlet distances_inline: Vec<f32> = points\n .iter()\n .map(|point| {\n let change = point - &origin;\n (change.x.powi(2) + change.y.powi(2)).sqrt()\n })\n .collect();\n\n// This version is *much* cleaner!\nlet distances_impl: Vec<f32> = points.iter().map(distance_from_impl(&origin)).collect();\nSponsors\n(Thanks to the couple people donating who opted out of the reward tier, as well. You know who you are!)
\nBecome a sponsor\n\nContact\n