On this page
  1. Copy
  2. Availability
  3. Syntax & Overview
  4. Notes & Pitfalls
  5. Example

Copy

Prev: str | Up: builtins | Next: Clone
Rel: builtins, Ownership, Borrowing & Lifetimes
Ref: Rust Docs — Copy
Tags: #public #prog #rust #builtins #tier/core


Availability

Built-in / Prelude (Marker Trait) — available with zero use imports.

Syntax & Overview

#[derive(Copy, Clone)] struct Point { x: f64, y: f64 }

Marks stack-only bitwise-copyable types so assignment copies instead of moving ownership.

Notes & Pitfalls

Example

#[derive(Copy, Clone, Debug, PartialEq)]
struct Point { x: i32, y: i32 }

fn main() {
    let p1 = Point { x: 3, y: 4 };
    let p2 = p1; // bitwise copied, not moved
    assert_eq!(p1.x + p2.y, 7);
}

Linked from

Related notes