New Rustacean  learning The Rust Programming Language

e025: Traits Deep Dive, Part III

Informações:

Sinopsis

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 RFC #1733: Trait Aliases RFC #255: Object Safety Ch. 17 in the Second Edition of The Rust Programming Language Huon Wilson’s post 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<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(&