rules about rust ownership -- copy,destroyed,move,borrow

reference

example code

fn foo<T>(_x: T) {
    // destroyed _x
}

fn stack_based() {
    // `x` will be allocated on current stack
    let x: u32 = 5;
    // *Copy* `x` into `y`
    let y: u32 = x;
    // the value gets copied at the call of foo(x)
    foo(x);
    // the copied `x` and `y` in `foo` will destroyed in foo
    foo(y);
    // `x` and `y` will destroyed(the destructor will be called)
}

// simple struct
struct Info1 {
    value: i32,
}

// Copy-able struct
#[derive(Copy, Clone)]
struct Info2 {
    value: i32,
}

fn copy_trait() {
    let info1 = Info1 { value: 12 };
    let info2 = Info2 { value: 12 };
    // info1 moved to foo, and destroyed in foo
    foo(info1);
    // println!("{:?}", info1.value);
    /*
error[E0382]: borrow of moved value: `info1`
  --> src/main.rs:32:22
   |
31 |     foo(info1);
   |         ----- value moved here
32 |     println!("{:?}", info1.value);
   |                      ^^^^^^^^^^^ value borrowed here after move
   |
   = note: move occurs because `info1` has type `Info1`, which does not implement the `Copy` trait
     */
    // info2 copied to foo
    foo(info2);
    println!("{:?}", info2.value);
    // info2 destroyed in here again

}

struct DestroyMe {
    my_name: String,
}

impl DestroyMe {
    fn new(name: &str) -> DestroyMe {
        println!("new DestroyMe: {:?}", name);
        DestroyMe { my_name: name.to_string() }

    }
}

// built-in Drop::drop trait method
impl Drop for DestroyMe {
    fn drop(&mut self) {
        println!("destroyed DestroyMe {:?}", self.my_name);
    }
}

fn destroyed_test() {
    // `233` will destroyed immediately
    println!("before new");
    DestroyMe::new("233");
    println!("after new");
    /*
before new
new DestroyMe: "233"
destroyed DestroyMe "233"
after new
     */

    // `234` will destroyed when func end
    println!("before let new");
    let _dm = DestroyMe::new("234");
    println!("after let new");
    /*
before let new
new DestroyMe: "234"
after let new
...
destroyed DestroyMe "234"
      */

    // `235` will destroyed in foo
    println!("before let new");
    let dm = DestroyMe::new("235");
    println!("after let new before foo");
    foo(dm);
    println!("after let foo");
    /*
before let new
new DestroyMe: "235"
after let new before foo
destroyed DestroyMe "235"
after let foo
      */
    // more detail check `scope`
}

fn main() {
    stack_based();
    copy_trait();
    destroyed_test();
}