What is the meaning of 'Temporary'

⚓ Rust    📅 2025-12-04    👤 surdeus    👁️ 2      

surdeus

Hi everyone, I'm new to Rust. I have some questions about the concept of Temporary, and I've done some research on it, but there are a few things I'm still unclear about:

fn main() {
     let s = &String::from("text");
}

Does Rust create a temporary variable containing String::from("text") in the above code? Or does temporary variable here refer to String::from("text")?

If Rust actually creates a 'temporary variable' to hold String::from("text"), will that variable be stored on the stack or the heap? And will String::from("text") be stored on the stack or the heap?

3 posts - 2 participants

Read full topic

🏷️ Rust_feed