如题,直接上代码了。内容涉及多个struct实例的比较,以及将struct本身作为函数的参数
struct Myc{
w:u32,
h:u32,
}
impl Myc{
fn call_bijiao(&self,other:&Myc) -> bool{
self.w > other.w
}
}
fn main(){
let t1 = Myc{w:6,h:7};
let t2 = Myc{w:5,h:3};
let t3 = Myc{w:8,h:13};
println!("{}",t1.call_bijiao(&t2));//true
println!("{}",t1.call_bijiao(&t3));//false
let t4 = Myc{w:5,h:6};
println!("{:?}",area(&t4));//30
}
fn area(i:&Myc) ->u32{
i.w*i.h
}