#Not understanding someone in Programming Rust 2nd Edition

1 messages · Page 1 of 1 (latest)

restive chasm
#

I am not understanding the difference between:

"We say that the variable’s lifetime must contain or enclose that of the reference borrowed from it."

And:

"We say that the reference’s lifetime must contain or enclose the variable’s."

Any help would be appreciated.

rain turret
#

Contain here means outlive. The variable must be alive before the reference is made and stay alive past when the reference is dropped.

restive chasm
#

Ok then what is the difference between the two quotes would you say

#

this is the diagram he gave

rain turret
#

This code will not compile.

restive chasm
#

it's probably not that ocmplex but it's not registering 4 me

rain turret
#

I'd say this: &x is given the name r. r is created after x so that's fine, but it needs to be dropped before x is dropped, which it isn't.

#

"the variable" here is x