类型初始化 / 类

//There are no classes in Rust
#[derive(Debug)]
#[allow(dead_code)]
struct Phone<'a>  {
    model: &'a str
}

#[derive(Debug)]
#[allow(dead_code)]
struct Employee<'a> {
    first_name: &'a str,
    last_name: &'a str,
    phone: Phone<'a>
}

impl Phone<'_> {
    fn new(model: &str) -> Phone {
        Phone { model: model }
    }
}

impl Employee<'_> {
    fn new<'a>(first_name: &'str, last_name:
        &'a str, phone: Phone<'a>) -> Employee<'a> {
        Employee {
            first_name: first_name, 
            last_name: last_name,
            phone: phone
        }
    }
}

let nokia_phone = Phone::new("Nokia 6610");

let kim = Employee::new("Victorya""Kim",
    Phone::new("iPhone 5"));

println!("nokia_phone is {:?}", nokia_phone);
println!("kim is {:?}", kim);