mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-05-15 23:26:48 +02:00
Clarification on references
This commit is contained in:
parent
529d4bf20c
commit
6bda89f34e
@ -11,9 +11,18 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
Some differences from C++:
|
||||
Some notes:
|
||||
|
||||
* We must dereference `ref_x` when assigning to it, similar to C pointers,
|
||||
* We must dereference `ref_x` when assigning to it, similar to C and C++ pointers.
|
||||
* Rust will auto-dereference in some cases, in particular when invoking
|
||||
methods (try `count_ones`).
|
||||
methods (try `ref_x.count_ones()`).
|
||||
* References that are declared as `mut` can be bound to different values over their lifetime.
|
||||
|
||||
<details>
|
||||
Key points:
|
||||
|
||||
* Be sure to note the difference between `let mut ref_x: &i32` and `let ref_x:
|
||||
&mut i32`. The first one represents a mutable reference which can be bound to
|
||||
different values, while the second represents a reference to a mutable value.
|
||||
|
||||
</details>
|
||||
|
Loading…
x
Reference in New Issue
Block a user