t_wの輪郭

Feedlyでフォローするボタン

メソッド記法

2022/2/18 1:27:00
struct Body {
    weight: f64,
    height: f64,
}

impl Body {
    fn bmi_calc(&self) -> f64 {
        self.weight/(self.height*self.height)
    }
}

fn main() {
    let body = Body{weight: 60., height: 1.7};
    let bmi = body.bmi_calc();
    println!("bmi: {}", bmi);   //20.761245674740486
}