Skip to content

Instantly share code, notes, and snippets.

@AurevoirXavier
Last active April 8, 2020 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AurevoirXavier/c485997bc0f9b7a5abae1ff67378f8fc to your computer and use it in GitHub Desktop.
Save AurevoirXavier/c485997bc0f9b7a5abae1ff67378f8fc to your computer and use it in GitHub Desktop.
[Rust] Confused About Lifetimes
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?
@AurevoirXavier
Copy link
Author


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment