Hello, I am still quite new to Rust and I am trying to learn how to deal properly with references.
I am trying to use .flat_map()
on a vector of length 3, that i create inside the function as follows
let points: Vec<(MyType, bool)> =
some_vec.flat_map(|[a,b,c]|
[
(MyType{a.some_property()}, false),
(MyType{b.some_property()}, true),
(MyType{c.some_property()}, true),
].into_iter()
)
.collect();
But it seems that flat_map
returns a reference to the tuples created, instead passing the ownership to the new function
value of type `Vec<(MyType, bool)>` cannot be built from `Iterator<Item=&(MyType, bool)>
If i then try to add a .map(|&t| t)
before .collect()
the compiler complains that
cannot return value referencing temporary value
returns a value referencing data owned by the current functionrustc(E0515)
printer.rs(226, 17): returns a value referencing data owned by the current function
printer.rs(226, 17): temporary value created here
I have tried searching on the various errors, but cant seem to find the right solution. So if anyone could point me in the right direction, I would greatly appriciate it!