Crates.io | painless_input |
lib.rs | painless_input |
version | 0.1.4 |
source | src |
created_at | 2023-09-07 16:59:41.577005 |
updated_at | 2023-09-14 16:52:09.293478 |
description | A simple input library with support for array input, validation, and pretty error messages. |
homepage | https://github.com/AHL00/painless_input |
repository | |
max_upload_size | |
id | 966401 |
size | 62,156 |
This is an easy to use input library crate. It automatically handles parsing errors and data validation with a simple syntax and good looking error messages.
use painless_input::input;
fn main() {
let num: u8 = input("Enter a number: ");
println!();
}
use painless_input::input_array;
fn main() {
let nums: Vec<u8> = input_array("Enter a list of numbers: ");
println!();
}
use painless_input::input_with_validation;
fn main() {
let validated_num = input_with_validation::<u8>("Enter a number between 0 and 10: ", Box::new(|value| {
if value < 0 || value > 10 {
Err("Number must be between 0 and 10")
} else {
Ok(())
}
}));
println!();
}