Crates.io | guessing_utils |
lib.rs | guessing_utils |
version | 1.0.4 |
source | src |
created_at | 2023-07-08 11:29:10.185407 |
updated_at | 2023-07-08 12:00:16.512533 |
description | Various guessing utilities for working with guesses in (0..101) number range. |
homepage | |
repository | https://github.com/RealKrazy/guessing_utilities |
max_upload_size | |
id | 911427 |
size | 10,150 |
This crate provides various guessing utilities for working with guesses in (0..101) number range. Check the documentation for more.
use guessing_utils;
use guessing_utils::Guess;
use std::io;
use std::cmp::Ordering;
fn main() {
println!("Guess the number!");
let secret_number = guessing_utils::gen_random();
loop {
println!("Please input your guess.");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
let guess: Guess = match guessing_utils::Guess::parse(&guess) {
Ok(val) => val,
Err(_) => continue,
};
println!("You guessed: {}", guess.value());
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => {
println!("You win!");
break;
}
}
}
}