Crates.io | prompted |
lib.rs | prompted |
version | 0.2.8 |
source | src |
created_at | 2023-02-16 01:22:05.582859 |
updated_at | 2023-11-16 05:52:23.296441 |
description | Macros for input and prompting. |
homepage | https://github.com/BartMassey/prompted |
repository | https://github.com/BartMassey/prompted |
max_upload_size | |
id | 786426 |
size | 20,317 |
Copyright © Bart Massey 2017 (Version 0.2.8)
This crate provides macros for easy non-newline-terminated flushed printing, and for input line reading. These macros are intended for new Rust users and for folks who need no more for simple applications.
Here's an example adapted from the "Guessing Game" example in The Rust Programming Language.
use std::cmp::Ordering;
use prompted::input;
fn main() {
println!("Guess the number!");
let n = 100;
let secret_number = 37;
loop {
let guess = input!("Please input your guess (1-{}): ", n);
let guess: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => continue,
};
println!("You guessed: {}", guess);
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => {
println!("You win!");
break;
}
}
}
}
This work is licensed under the "MIT License". Please
see the file LICENSE
in the source distribution of this
software for license terms.
Thanks to the cargo-readme
crate for generation of this README
.