Function understand_copy_clone

Source
pub fn understand_copy_clone()
Expand description

§Rust 语义:Move 语义 与 Copy 语义

  • 理解 Copy:Clone https://doc.rust-lang.org/std/marker/trait.Copy.html
struct A;

// 没用,自己实现Copy和Clone无法改变编译器默认行为
impl Clone for A {
    fn clone(&self) -> Self {
        println!("from Custom Copy: Clone");
        *self
    }
}

impl Copy for A {}


fn main(){
    let a = A;
    let b = a;
}