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

Update lifetimes-data-structures.md (#224)

* Update lifetimes-data-structures.md

The example is quite simple, but in it's simplicity it may raise the question why do we even need lifetimes in the structs? Isn't it obvious that the referenced value should always outlive the struct? This sentence tries to explain that more complex cases exist.

* Fix typo

Co-authored-by: Andrew Walbran <qwandor@google.com>
This commit is contained in:
Igor Petruk 2023-01-23 11:37:38 +00:00 committed by GitHub
parent 473fd02be7
commit 71ce061cc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,5 +26,5 @@ fn main() {
* If `text` is consumed before the end of the lifetime of `fox` (or `dog`), the borrow checker throws an error.
* Types with borrowed data force users to hold on to the original data. This can be useful for creating lightweight views, but it generally makes them somewhat harder to use.
* When possible, make data structures own their data directly.
* Some structs with multiple references inside can have more than one lifetime annotation. This can be necessary if there is a need to describe lifetime relationships between the references themselves, in addition to the lifetime of the struct itself. Those are very advanced use cases.
</details>