You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-27 11:08:45 +02:00
Merge pull request #154 from fbornhofen/speaker-notes
Speaker notes for box.md, rc.md, option-result.md
This commit is contained in:
@ -28,3 +28,10 @@ from `T` directly on a `Box<T>`][2].
|
|||||||
|
|
||||||
[1]: https://doc.rust-lang.org/std/boxed/struct.Box.html
|
[1]: https://doc.rust-lang.org/std/boxed/struct.Box.html
|
||||||
[2]: https://doc.rust-lang.org/std/ops/trait.Deref.html#more-on-deref-coercion
|
[2]: https://doc.rust-lang.org/std/ops/trait.Deref.html#more-on-deref-coercion
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
* `Box` is like `std::unique_ptr` in C++.
|
||||||
|
* In the above example, you can even leave out the `*` in the `println!` statement thanks to `Deref`.
|
||||||
|
|
||||||
|
</details>
|
||||||
|
@ -12,3 +12,14 @@ fn main() {
|
|||||||
println!("idx: {idx:?}");
|
println!("idx: {idx:?}");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
* `Option` and `Result` are widely used not just in the standard library.
|
||||||
|
* `Option<&T>` has zero space overhead compared to `&T`.
|
||||||
|
* `Result` is the standard type to implement error handling as we will see on Day 3.
|
||||||
|
* `binary_search` returns `Result<usize, usize>`.
|
||||||
|
* If found, `Result::Ok` holds the index where the element is found.
|
||||||
|
* Otherwise, `Result::Err` contains the index where such an element should be inserted.
|
||||||
|
|
||||||
|
</details>
|
||||||
|
@ -22,3 +22,11 @@ context.
|
|||||||
[1]: https://doc.rust-lang.org/std/rc/struct.Rc.html
|
[1]: https://doc.rust-lang.org/std/rc/struct.Rc.html
|
||||||
[2]: https://doc.rust-lang.org/std/cell/index.html
|
[2]: https://doc.rust-lang.org/std/cell/index.html
|
||||||
[3]: ../concurrency/shared_state/arc.md
|
[3]: ../concurrency/shared_state/arc.md
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
* Like C++'s `std::shared_ptr`.
|
||||||
|
* `clone` is cheap: creates a pointer to the same allocation and increases the reference count.
|
||||||
|
* `make_mut` actually clones the inner value if necessary ("clone-on-write") and returns a mutable reference.
|
||||||
|
|
||||||
|
</details>
|
||||||
|
Reference in New Issue
Block a user