You can dereference and reborrow the mutable references, then add them to a new Vec
:
fn main() {
let mut st = String::new();
let mut_vec = vec![&mut st];
let immut_vec = mut_vec.into_iter().map(|x| &*x).collect();
cool_func(immut_vec);
}
fn cool_func(_: Vec<&String>) {}
Note however, that this consumes the original Vec
- you can't really get around this, as if the original Vec
still existed, you'd have both mutable and immutable references to the same piece of data, which the compiler will not allow.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…