Skip to content

Rust Ownership — The Ownership Model, Move Semantics, and Copy Types

DodaTech Updated 2026-06-28 1 min read

In this tutorial, you will learn about Rust Ownership. We cover key concepts, practical examples, and best practices to help you master this topic.

Rust ownership rules: each value has one owner, ownership transfers on move, and Copy types duplicate automatically instead of moving.

What You'll Learn

  • Ownership rules
  • Move semantics
  • Clone vs Copy
  • Ownership in functions

Why It Matters

Ownership eliminates Garbage Collection and prevents memory bugs. DodaZIP relies on ownership for safe file handle management without GC.

Real-World Use

Memory-safe systems programming, resource management, no-GC high-performance code.

fn main() {
    // Ownership rules
    let s1 = String::from("hello");
    let s2 = s1;  // Move: s1 is no longer valid
    // println!("{}", s1); // Error!

    // Clone for deep copy
    let s3 = String::from("world");
    let s4 = s3.clone();
    println!("{} {}", s3, s4); // Both valid

    // Copy types (stack-only)
    let x = 5;
    let y = x;  // Copy, not move
    println!("{} {}", x, y); // Both valid

    // Ownership in functions
    let s = String::from("hello");
    take_ownership(s);
    // println!("{}", s); // Error: moved
}

fn take_ownership(s: String) {
    println!("Took ownership of: {}", s);
} // s dropped here

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro