use std::fmt::Debug;
struct User{
name:String,
email:String,
age:u8,
active:bool,
}
#[derive(Debug)]
struct Rectamgle {
width:u32,
height:u32,
}
impl Rectamgle {
fn get_area(&self)->u32{
self.width * self.height
}
fn can_hold(&self,other:&Rectamgle) -> bool{
self.width > other.width && self.height > other.height
}
fn createSquare(size:u32) ->Rectamgle{
Rectamgle { width: size, height: size }
}
}
fn main(){
let user = get_user("xm",12);
let user2 = User{
email:String::from("bc@qq.com"),
..user
};
println!("{},{}",user2.email,user2.name);
struct Color(u8,u8,u8);
let black = Color(0,0,0);
let rect = Rectamgle{
width:30,
height:60
};
println!("{}", area(&rect)); println!("{:#?}",rect);
println!("area {}",rect.get_area());
let rect1 = Rectamgle::createSquare(20);
println!("{}", rect.can_hold(&rect1))
}
fn area(rect:&Rectamgle)->u32{
rect.width * rect.height
}
fn get_user(name:&str,age:u8)->User{
let mut user = User {
name:String::from(name),
email:String::from(""),
age,
active:false
};
user.email = String::from("abc@163.com");
return user;
}