You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-12-22 22:51:12 +02:00
Miscellaneous minor improvements (#2370)
This commit is contained in:
@@ -38,6 +38,8 @@ fn x_axis(x: &i32) -> &(i32, i32) {
|
||||
|
||||
<details>
|
||||
|
||||
- References can never be null in Rust, so null checking is not necessary.
|
||||
|
||||
- A reference is said to "borrow" the value it refers to, and this is a good
|
||||
model for students not familiar with pointers: code can use the reference to
|
||||
access the value, but is still "owned" by the original variable. The course
|
||||
|
||||
@@ -20,7 +20,6 @@ fn main() {
|
||||
```
|
||||
|
||||
- Slices borrow data from the sliced type.
|
||||
- Question: What happens if you modify `a[3]` right before printing `s`?
|
||||
|
||||
<details>
|
||||
|
||||
@@ -43,10 +42,4 @@ fn main() {
|
||||
- Slices always borrow from another object. In this example, `a` has to remain
|
||||
'alive' (in scope) for at least as long as our slice.
|
||||
|
||||
- The question about modifying `a[3]` can spark an interesting discussion, but
|
||||
the answer is that for memory safety reasons you cannot do it through `a` at
|
||||
this point in the execution, but you can read the data from both `a` and `s`
|
||||
safely. It works before you created the slice, and again after the `println`,
|
||||
when the slice is no longer used.
|
||||
|
||||
</details>
|
||||
|
||||
Reference in New Issue
Block a user