Crates.io | casual |
lib.rs | casual |
version | 0.2.0 |
source | src |
created_at | 2020-04-08 07:38:26.480705 |
updated_at | 2020-10-04 17:53:17.126695 |
description | Simple crate for parsing user input. |
homepage | https://github.com/rossmacarthur/casual |
repository | https://github.com/rossmacarthur/casual |
max_upload_size | |
id | 227566 |
size | 26,461 |
Simple crate for parsing user input.
Add the following dependency to your Cargo.toml
.
[dependencies]
casual = "0.2"
Rust type inference is used to know what to return.
let username: String = casual::prompt("Please enter your name: ").get();
FromStr
is used to parse the input, so you can read any type that implements
FromStr
.
let age: u32 = casual::prompt("Please enter your age: ").get();
.matches()
can be used to validate the input data.
let age: u32 = casual::prompt("Please enter your age again: ").matches(|x| *x < 120).get();
A convenience function confirm
is provided for getting a yes or no answer.
if casual::confirm("Are you sure you want to continue?") {
// continue
} else {
panic!("Aborted!");
}
Licensed under either of
at your option.