mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-01-18 04:23:14 +02:00
Include notes on when to use lifetime annotations (#1616)
This addresses > Could use more clarity on why or when people would want to use lifetimes -- when is it worth going to the trouble of not Cloning, etc. in #1565.
This commit is contained in:
parent
9b439b34ab
commit
09aa70b963
@ -68,4 +68,10 @@ This won't compile, demonstrating that the annotations are checked for validity
|
||||
by the compiler. Note that this is not the case for raw pointers (unsafe), and
|
||||
this is a common source of errors with unsafe Rust.
|
||||
|
||||
Students may ask when to use lifetimes. Rust borrows _always_ have lifetimes.
|
||||
Most of the time, elision and type inference mean these don't need to be
|
||||
written out. In more complicated cases, lifetime annotations can help resolve
|
||||
ambiguity. Often, especially when prototyping, it's easier to just work with
|
||||
owned data by cloning values where necessary.
|
||||
|
||||
</details>
|
||||
|
Loading…
Reference in New Issue
Block a user