Why this does not compile:
fn main() {
let mut b = Box::new(Vec::new());
b.push(Vec::new());
b.get_mut(0).unwrap().push(1);
}
While doing this:
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 it 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 for me are conceptually the same - Vector box of vectors vectors and vector vectors vectors vectors. But the latter leads to the fact that each vector is mutable, while the first makes the inner vector unchanged.
source
share