5 構造体 #5
lemonadern
started this conversation in
General
Replies: 4 comments 9 replies
-
構造体
struct User {
username: String,
email: String,
sign_in_count: u64,
active: bool,
} |
Beta Was this translation helpful? Give feedback.
6 replies
-
構造体のprintf デバッグ
Rustでは、 |
Beta Was this translation helpful? Give feedback.
1 reply
-
メソッド記法
#[derive(Debug)]
struct Rectangle {
width: u32,
height: u32,
}
impl Rectangle {
fn area(&self) -> u32 {
self.width * self.height
}
}
fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
println!(
"The area of the rectangle is {} square pixels.",
rect1.area()
);
}
|
Beta Was this translation helpful? Give feedback.
1 reply
-
関連関数
// 1辺の長さだけを受け取り、正方形の`Rectangle` を返す関連関数 `square`
impl Rectangle {
fn square(size: u32) -> Rectangle {
Rectangle { width: size, height: size }
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
https://doc.rust-jp.rs/book-ja/ch05-00-structs.html
Beta Was this translation helpful? Give feedback.
All reactions