Understanding where &str data is stored in Rust
This is an easy Rust language-knowledge question that tests your grasp of memory layout and the distinction between string types in Rust. It focuses on the difference between a string reference and the data it points to, and where that data actually lives at runtime.
To answer questions like this, you need to understand Rust's memory model: how the stack and heap differ, where the compiler places different kinds of data, and how references relate to the underlying storage. This is foundational knowledge for writing correct Rust code and reasoning about performance and lifetimes.
- Stack vs. heap allocation in Rust
- String types and their internal representation
- The relationship between references and owned data
- Compile-time string literals vs. runtime allocations