- // We can convert any vector of digits into a number, by removing trailing zeros. The `mut`
+ // Any vector of digits, which meets the structure of BigInt's `data` field, can be easily
+ // converted into a big number just by removing trailing zeros. The `mut`
// declaration for `v` here is just like the one in `let mut ...`: We completely own `v`, but Rust
// still asks us to make our intention of modifying it explicit. This `mut` is *not* part of the
// type of `from_vec` - the caller has to give up ownership of `v` anyway, so they don't care anymore
// declaration for `v` here is just like the one in `let mut ...`: We completely own `v`, but Rust
// still asks us to make our intention of modifying it explicit. This `mut` is *not* part of the
// type of `from_vec` - the caller has to give up ownership of `v` anyway, so they don't care anymore
Text(String),
}
//@ Now consider the following piece of code. Like above, `n` will be a reference to a part of `var`,
Text(String),
}
//@ Now consider the following piece of code. Like above, `n` will be a reference to a part of `var`,
-//@ and since we wrote `ref mut`, the reference will be exclusive and mutable. In other words, right after the match, `ptr`
+//@ and since we wrote `ref mut`, the reference will be unique and mutable. In other words, right after the match, `ptr`
//@ points to the number that's stored in `var`, where `var` is a `Number`. Remember that `_` means
//@ "we don't care".
fn work_on_variant(mut var: Variant, text: String) {
//@ points to the number that's stored in `var`, where `var` is a `Number`. Remember that `_` means
//@ "we don't care".
fn work_on_variant(mut var: Variant, text: String) {
//@ I hope this example clarifies why Rust has to rule out mutation in the presence of aliasing *in general*,
//@ not just for the specific case of a buffer being reallocated, and old pointers becoming hence invalid.
//@ I hope this example clarifies why Rust has to rule out mutation in the presence of aliasing *in general*,
//@ not just for the specific case of a buffer being reallocated, and old pointers becoming hence invalid.