1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-04 08:08:09 +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:
Martin Geisler 2023-01-11 14:49:03 +01:00 committed by GitHub
commit 6019a946d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View File

@ -28,3 +28,10 @@ from `T` directly on a `Box<T>`][2].
[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
<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>

View File

@ -12,3 +12,14 @@ fn main() {
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>

View File

@ -22,3 +22,11 @@ context.
[1]: https://doc.rust-lang.org/std/rc/struct.Rc.html
[2]: https://doc.rust-lang.org/std/cell/index.html
[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>