Corelib
Copy
pub trait Copy
#[derive(Drop)] struct Point { x: u128, y: u128, } fn main() { let p1 = Point { x: 5, y: 10 }; foo(p1); foo(p1); // error: Variable was previously moved. } fn foo(p: Point) {}
#[derive(Copy, Drop)] struct Point { x: u128, y: u128, } fn main() { let p1 = Point { x: 5, y: 10 }; foo(p1); foo(p1); // works: `p1` is copied when passed to `foo` } fn foo(p: Point) {}
Was this page helpful?