Copy
fn main() { let s1 = 1; let s2 = s1; println!("s1 is {}", s1); println!("s2 is {}", s2); //Explained later #[derive(Debug, Clone, Copy)] struct Rectangle { width: u32, height: u32, }; let rect1 = Rectangle { width: 2, height: 3, }; let rect2 = rect1; println!("rect1 is {:?}", rect1); println!("rect2 is {:?}", rect2); }
-
Copy trait
- Memory allocated on stack
-
Type implementing Drop trait cannot marked as Copy
-
Examples of copy:
- Primitive types
- Group of copy