Last active
April 8, 2020 06:14
-
-
Save aurexav/c485997bc0f9b7a5abae1ff67378f8fc to your computer and use it in GitHub Desktop.
[Rust] Confused About Lifetimes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Test { | |
x: i32 | |
}; | |
let a; | |
{ | |
let b = &Test { x: 42 }; // Temporary struct Test put on the stack | |
a = b; | |
} // Temporary Test dropped here? | |
println!("{}", a.x); // Temporary Test used here? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alice:
What happened here is the same that happens to a literal string. The constant is hard coded somewhere in the binary and the reference is a 'static reference that points into the executable.
More detail: https://users.rust-lang.org/t/confused-about-lifetimes/34000