Why this doesn't compile:
fn main() {
let mut b = Box::new(Vec::new());
b.push(Vec::new());
b.get_mut(0).unwrap().push(1);
}
While this does:
fn main() {
let a = Box::new(Vec::new());
let mut b = *a;
b.push(Vec::new());
b.get_mut(0).unwrap().push(1);
}
And also this does:
fn main() {
let mut b = Vec::new();
b.push(Vec::new());
b.get_mut(0).unwrap().push(Vec::new());
b.get_mut(0).unwrap().get_mut(0).unwrap().push(1)
}
The first and third one for me are the conceptually the same - Box
of a Vec
tor of Vec
tors of integers and a Vec
tor of Vec
tor of Vec
tors of integers, but the last one results in each vector being mutable, whereas the first one makes the inner vector immutable.