Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/rust-lang-uz/book
Browse files Browse the repository at this point in the history
  • Loading branch information
0xf90c committed Jun 14, 2024
2 parents a863de6 + 3a84ece commit 4948ca7
Show file tree
Hide file tree
Showing 22 changed files with 752 additions and 674 deletions.
17 changes: 17 additions & 0 deletions rustbook-en/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
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct ImportantExcerpt<'a> {

fn main() {
let novel = String::from("Call me Ishmael. Some years ago...");
let first_sentence = novel.split('.').next().expect("Could not find a '.'");
let first_sentence = novel.split('.').next().unwrap();
let i = ImportantExcerpt {
part: first_sentence,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a> ImportantExcerpt<'a> {

fn main() {
let novel = String::from("Call me Ishmael. Some years ago...");
let first_sentence = novel.split('.').next().expect("Could not find a '.'");
let first_sentence = novel.split('.').next().unwrap();
let i = ImportantExcerpt {
part: first_sentence,
};
Expand Down
Loading

0 comments on commit 4948ca7

Please sign in to comment.