I've got a vector of mutable references:
type T = String;
let mut mut_vec: Vec<&mut T> = vec![];
I want to pass (a copy of) it into a function that takes a vector of immutable references:
fn cool_func(mut immut_vec: Vec<&T>) -> bool {false}
How can I do this?
You can dereference and reborrow the mutable references, then add them to a new
Vec
:Note however, that this consumes the original
Vec
- you can't really get around this, as if the originalVec
still existed, you'd have both mutable and immutable references to the same piece of data, which the compiler will not allow.