Mutable reference to non mutable value

I have the following code:

let mut q_r:Vec<Thing> = vec![];
let things:[Thing; 8] = make_things();
q_r.append(&mut Vec::from(quarters));

things is not mutable, but I can make a mutable reference to it.

Can we have a mutable reference to a immutable object in Rust? What does that actually mean?

1 Like

That's not what you did, though. You moved thing to create a Vec from it, then took a &mut to the temporary.

I suspect what you're looking for is