Function custom_types

Source
pub fn custom_types()
Expand description

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

自定义数据类型:

// #[derive(Copy, Clone)]
struct A;

// #[derive(Copy, Clone)]
struct Point(u32);

// #[derive(Copy, Clone)]
struct Member {
    name: &'static str,
    age: u32,
}

// #[derive(Copy, Clone)]
struct Person {
    name: String,
    age: u32,
}

fn main(){
    let a = A;
    let b = a;
    println!("{:?}", a);  // work

    let a = Point(60);
    let b = a;
    println!("{:?}", a);  // work

    let a = Member{name: "Alex", age: "18"};
    let b = a;

    let a = Member{name: "Alex".to_string(), age: "18"};
    let b = a;
}