記法
2020/9/11 12:56:00
```txt
+(100x100)https://example.com/img.png
+(100x100)https://example.com/img.png
+(100x100)https://example.com/img.png
```左寄せ・中央寄せ・右寄せは
+
前のスペースで調整。```txt
++png++ 左側に画像が回り込む。
```
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
}
多くは前の個体の値を使用しつつ、変更する箇所もある形で新しい個体を生成できる記法
struct User {
username: String,
email: String,
sign_in_count: u64,
active: bool,
}
fn main() {
let user1 = User {
username: String::from("username1"),
email: String::from("[email protected]"),
active: true,
sign_in_count: 1,
};
let user2 = User {
username: String::from("username2"),
email: String::from("[email protected]"),
..user1 //構造体更新記法でuser1から残りの欄の値を引き継ぐ
};
println!("{}", user2.username); //username2
}