mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-04-22 13:38:04 +08:00
28 lines
416 B
Rust
28 lines
416 B
Rust
pub struct Guess {
|
|
value: i32,
|
|
}
|
|
|
|
// ANCHOR: here
|
|
// --snip--
|
|
impl Guess {
|
|
pub fn new(value: i32) -> Guess {
|
|
if value < 1 {
|
|
panic!("Guess value must be between 1 and 100, got {value}.");
|
|
}
|
|
|
|
Guess { value }
|
|
}
|
|
}
|
|
// ANCHOR_END: here
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
#[should_panic]
|
|
fn greater_than_100() {
|
|
Guess::new(200);
|
|
}
|
|
}
|