mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
866 B
48 lines
866 B
#[derive(Debug)]
|
|
struct Rectangle {
|
|
width: u32,
|
|
height: u32,
|
|
}
|
|
|
|
// ANCHOR: here
|
|
// --snip--
|
|
impl Rectangle {
|
|
fn can_hold(&self, other: &Rectangle) -> bool {
|
|
self.width < other.width && self.height > other.height
|
|
}
|
|
}
|
|
// ANCHOR_END: 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));
|
|
}
|
|
|
|
#[test]
|
|
fn smaller_cannot_hold_larger() {
|
|
let larger = Rectangle {
|
|
width: 8,
|
|
height: 7,
|
|
};
|
|
let smaller = Rectangle {
|
|
width: 5,
|
|
height: 1,
|
|
};
|
|
|
|
assert!(!smaller.can_hold(&larger));
|
|
}
|
|
}
|