mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-24 21:32:15 +08:00
25 lines
383 B
Rust
Executable File
25 lines
383 B
Rust
Executable File
#[derive(Debug)]
|
|
struct Rectangle {
|
|
width: u32,
|
|
height: u32,
|
|
}
|
|
|
|
// ANCHOR: here
|
|
impl Rectangle {
|
|
fn width(&self) -> bool {
|
|
self.width > 0
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let rect1 = Rectangle {
|
|
width: 30,
|
|
height: 50,
|
|
};
|
|
|
|
if rect1.width() {
|
|
println!("The rectangle has a nonzero width; it is {}", rect1.width);
|
|
}
|
|
}
|
|
// ANCHOR_END: here
|