Rust Systems & Tokio (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is Move Semantics in Rust?
junior LevelrustBasic
In Simple Words: When assigning a heap-allocated variable to another, Rust moves ownership rather than making a deep copy:
let s1 = String::from("hello");let s2 = s1;- Ownership of the heap buffer is transferred to
s2. - Variable
s1is invalidated by the compiler! Attempting to accesss1results in a compile-time error:use of moved value: s1. - Prevents double-free memory bugs at compile time with zero runtime cost.