What's the difference between trait Copy and Clone?


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

fn main() {
    let a = Point{x:3,y:4};
    let b = a; // line#1:  call copy method
    
    let c = b.clone(); // is some difference here with last statement line#1 ?

   println!("origin={:?} copied={:?} cloned={:?}",a,b,c);
}

#2

http://doc.rust-lang.org/stable/book/ownership.html#copy-types

Clone is explained here http://doc.rust-lang.org/stable/std/clone/index.html

The short explanation is “Clone is a way of copying a type that can run arbitrary code. Copy is a way of copying a type that just takes a memcpy.” Since Clone is more general than Copy, you can automatically make anything Copy Clone as well.

In your case, they’re the same. you’re just using a different method.