reading the chapter 8 in The Rust programming Language book.
Well, they put this snippet that generate an error:
let v = vec![1, 2, 3, 4, 5];
let third: &i32 = &v[2];
v.push(6);
Throw a compilation error, I understand why it happens, because I cannot borrow v as mutable when I borrowed it before as immutable. Perfect, I understand it.
But what if I want to display a element of v vector, and then I want to push it a new element.
What can I do in this situation?
The book don't cover it.
you can't borrow it as mutable because it is not declared as mutable.
Обсуждают сегодня