Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport changes to ch 9 and 10 #3946

Merged
merged 7 commits into from
May 28, 2024
17 changes: 17 additions & 0 deletions listings/ch09-error-handling/listing-09-13/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pub struct Guess {
value: i32,
}

impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 || value > 100 {
panic!("Guess value must be between 1 and 100, got {value}.");
}

Guess { value }
}

pub fn value(&self) -> i32 {
self.value
}
}
21 changes: 1 addition & 20 deletions listings/ch09-error-handling/listing-09-13/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
use guessing_game::Guess;
use rand::Rng;
use std::cmp::Ordering;
use std::io;

// ANCHOR: here
pub struct Guess {
value: i32,
}

impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 || value > 100 {
panic!("Guess value must be between 1 and 100, got {value}.");
}

Guess { value }
}

pub fn value(&self) -> i32 {
self.value
}
}
// ANCHOR_END: here

fn main() {
println!("Guess the number!");

Expand Down
Loading