DEV Community

Discussion on: Higher-Order Functions in Rust

Collapse
 
jay profile image
Jay

I implemented a simplified version, of your pure functions. Used the standard map to map over rows, and some other goodies.

I suggest to use vec![init_value;size] instead of creating and pushing vec(s).

I used pass by value in Boxed case as passing by value for primitives is trivial, they implement Copy trait.

Rust Playground

Collapse
 
deciduously profile image
Ben Lovy • Edited

Way better! I was specifically trying to avoid map but you're definitely right about using vec! and passing by value for this function.

Using the trait object in the parameter list is better for the local closure version too.