1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-12 05:24:12 +02:00

Add speaker notes for lifetimes-data-structures.md

This commit is contained in:
Fabian Bornhofen 2023-01-12 19:36:40 +01:00
parent 9c652d06aa
commit 77f24ffab7

View File

@ -20,3 +20,11 @@ fn main() {
}
```
<details>
* In the above example, the annotation on `Highlight` enforces that the data underlying the contained `&str` lives at least as long as any instance of `Highlight` that uses that data.
* If `text` is consumed before the end of the lifetime of `fox` (or `dog`), the borrow checker throws an error.
* Data structures with borrowed data force users to hold on to the original data structure. This can be useful for creating lightweight views, but generally make them somewhat harder to use.
* When appropriate, consider creating data structures that own data directly.
</details>