I\'ve got a vector of mutable references:
struct T;
let mut mut_vec: Vec<&mut T> = vec![];
If you need to actually convert, see Joe Clay's answer. However, you might not need to convert in the first place!
Instead of changing the argument, change the function so that it accepts both mutable and immutable references. Here we use Borrow to abstract over both:
use std::borrow::Borrow;
fn main() {
let mut st = String::new();
let mut_vec = vec![&mut st];
cool_func(mut_vec);
let immut_vec = vec![&st];
cool_func(immut_vec);
}
fn cool_func(_: Vec)
where
S: Borrow,
{
}
See also: