diff --git a/README.md b/README.md index 58ab2db..37c10de 100644 --- a/README.md +++ b/README.md @@ -33,20 +33,19 @@ fn main() { Guessing game ```rust -use std::cmp::Ordering; use simple_std::{prompt, random_int_range}; fn main() { let number = random_int_range(0..100); loop { let input = prompt("Guess: ").parse::().expect("not a number"); - match input.cmp(&number) { - Ordering::Less => println!("Too Small"), - Ordering::Greater => println!("Too Big"), - Ordering::Equal => { - println!("You win!"); - break; - } + if input < number { + println!("Higher"); + } else if input > number { + println!("Lower"); + } else { + println!("Correct!"); + break; } } } diff --git a/src/lib.rs b/src/lib.rs index 6a42064..9a48398 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ //! //! # Example: guessing game //! ``` -//! use std::cmp::Ordering; //! use simple_std::{prompt, random_int_range}; //! //! let number = random_int_range(0..100); @@ -11,18 +10,17 @@ //!# random_int_range(0..100).to_string() //!# } //! let input = prompt("guess: ").parse::().expect("not a number"); -//! match input.cmp(&number) { -//! Ordering::Less => println!("Too Small"), -//! Ordering::Greater => println!("Too Big"), -//! Ordering::Equal => { -//! println!("You win!"); -//! break; -//! } +//! if input < number { +//! println!("Higher"); +//! } else if input > number { +//! println!("Lower"); +//! } else { +//! println!("Correct!"); +//! break; //! } //! } //! ``` - pub use io::{input, prompt}; pub use random::{random_float, random_int_range}; @@ -92,9 +90,9 @@ mod random { /// /// # Why is this not in std? /// - /// Rust aims to be correct, that's why its major random number library is cryptographically secure, - /// meaning its randomness can't easily be guessed. And cryptographically secure random number generation - /// is a big task, that's why it has its own crate. + /// Rust aims to be correct, that's why it's major random number library is cryptographically secure, + /// meaning it's randomness can't easily be guessed. And cryptographically secure random number generation + /// is a big task, that's why it has it's own crate. pub fn random_float() -> f64 { ((random_u64() >> 11) as f64) / ((1u64 << 53) as f64) } @@ -123,7 +121,7 @@ mod random { range.start + ((random_u64() as i32).abs() % difference) } - /// generates a pseudo-random u64 + /// generates a pseudo-random u32 fn random_u64() -> u64 { use std::sync::atomic::{AtomicU64, Ordering};