You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The whole idea of creating a function that accepts lifetime annotation that does not correspond to any input nor output, but still has an effect on references inside it made me rethink again how lifetimes work on fundamental level.
I think this chapter would benefit from more visual explanation. For example, comment under failed_borrow(); line specifies that its 'a "defaults to 'static", but 'static is a tricky concept for beginners, since it doesn't necessarily mean "entire duration of a program". I'm honestly not sure if in this particular case lines should look like this:
When it comes to failed_borrow()'s body, does it even make sense to draw lines inside it, since the lifetime "goes outside"? Or maybe it could be drawn like this:
fn failed_borrow<'a>() { ---------------------------------| `'a` AKA `'static`
let _x = 12; |
|
// ERROR: `_x` does not live long enough |
let _y: &'a i32 = &_x; ----|`&_x`'s lifetime |
} ----------------------------| oops! |
|
... till the end of the program
Maybe print_refs()'s example could also benefit from this kind of visual feedback.
The text was updated successfully, but these errors were encountered:
The whole idea of creating a function that accepts lifetime annotation that does not correspond to any input nor output, but still has an effect on references inside it made me rethink again how lifetimes work on fundamental level.
I think this chapter would benefit from more visual explanation. For example, comment under
failed_borrow();
line specifies that its'a
"defaults to'static
", but'static
is a tricky concept for beginners, since it doesn't necessarily mean "entire duration of a program". I'm honestly not sure if in this particular case lines should look like this:Or like this:
When it comes to
failed_borrow()
's body, does it even make sense to draw lines inside it, since the lifetime "goes outside"? Or maybe it could be drawn like this:Maybe
print_refs()
's example could also benefit from this kind of visual feedback.The text was updated successfully, but these errors were encountered: