Closed
Description
In section 4.8, "The details" subheading, while explaining ownership with the following code example:
let v = vec![1, 2, 3];
let mut v2 = v;
the book suddenly switches to v1
instead of v
after the v2.truncate
example.
It would violate Rust’s safety guarantees by introducing a data race if one could access both v and v2 at the same time.
For example if we truncated the vector to just two elements through v2:
v2.truncate(2);and v1 were still accessible we'd end up with an invalid vector since v1 would not know that the heap data has been truncated.
The book continues to use v1
for the rest of the paragraph. But v1
does not appear in any of the preceding code segments.