mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-05-05 04:58:03 +08:00
33 lines
572 B
Rust
33 lines
572 B
Rust
#[derive(Debug)]
|
|
struct Rectangle {
|
|
width: u32,
|
|
height: u32,
|
|
}
|
|
|
|
impl Rectangle {
|
|
fn can_hold(&self, other: &Rectangle) -> bool {
|
|
self.width > other.width && self.height > other.height
|
|
}
|
|
}
|
|
|
|
// ANCHOR: here
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn larger_can_hold_smaller() {
|
|
let larger = Rectangle {
|
|
width: 8,
|
|
height: 7,
|
|
};
|
|
let smaller = Rectangle {
|
|
width: 5,
|
|
height: 1,
|
|
};
|
|
|
|
assert!(larger.can_hold(&smaller));
|
|
}
|
|
}
|
|
// ANCHOR_END: here
|