Skip to main content
InterviewHubPRO
Section Overview
Q2

Question 2 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

4%
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 s1 is invalidated by the compiler! Attempting to access s1 results in a compile-time error: use of moved value: s1.
  • Prevents double-free memory bugs at compile time with zero runtime cost.