guessing_utils

Crates.ioguessing_utils
lib.rsguessing_utils
version1.0.4
sourcesrc
created_at2023-07-08 11:29:10.185407
updated_at2023-07-08 12:00:16.512533
descriptionVarious guessing utilities for working with guesses in (0..101) number range.
homepage
repositoryhttps://github.com/RealKrazy/guessing_utilities
max_upload_size
id911427
size10,150
Krazy Dev (RealKrazy)

documentation

README

Guessing utilities

This crate provides various guessing utilities for working with guesses in (0..101) number range. Check the documentation for more.

Fully functional example

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;
            }
        }
    }
}
Commit count: 8

cargo fmt