Type mismatches resolving a closure that takes arguments by reference

The short version is that there’s a difference between the lifetimes that are inferred if the closure is written inline or stored as a variable. Write the closure inline and remove all the extraneous types: fn test(points: &[Point]) -> (&Point, f32) { let init = points.first().expect(“No initial”); fold(&points, (init, 0.), |(q, max_d), p| { let … Read more

Sharing a struct with trait objects as properties across threads

I find the error message pretty straightforward: the trait std::marker::Send is not implemented for Expr + ‘static required because of the requirements on the impl of std::marker::Send for std::sync::Arc<Expr + ‘static> required because it appears within the type Container required because of the requirements on the impl of std::marker::Send for std::sync::Arc<Container> required because it appears … Read more

Why does my variable not live long enough?

The problem is that string is created in your function and will be destroyed when the function returns. The vector you want to return contains slices of string, but those will not be valid outside of your function. If you’re not terribly worried about performance, you can return a Vec<String> from your function. You just … Read more