ownership
Rust Stack and heap: a conceptual memory model
A stack is commonly used for call frames and local storage; heap allocation provides storage with a lifetime managed through an allocator. A nonempty String owns a growable UTF-8 buffer. Source-level locals need not physically reside on the stack, and optimization can change storage choices. Expected output (not executed): 3 Tea bytes: 3 Why: The number and the string have different representations; the displayed result does not reveal their physical addresses. Common mistake: Assuming all fixed-size values are on the stack or that heap storage makes a value non-Copy.
Formal Syntax & Structure
rust syntaxrust
let count = 3_i32; let text = String::from("...");Working Example
Example Snippetrust
fn main() { let count = 3_i32; let label = String::from("Tea"); println!("{count} {label}"); println!("bytes: {}", label.len());}