4 releases

0.2.0 Oct 4, 2020
0.1.2 Jul 20, 2020
0.1.1 Apr 8, 2020
0.1.0 Apr 8, 2020

#1267 in Rust patterns

Download history 144/week @ 2024-08-04 201/week @ 2024-08-11 117/week @ 2024-08-18 377/week @ 2024-08-25 200/week @ 2024-09-01 189/week @ 2024-09-08 130/week @ 2024-09-15 233/week @ 2024-09-22 151/week @ 2024-09-29 113/week @ 2024-10-06 138/week @ 2024-10-13 91/week @ 2024-10-20 134/week @ 2024-10-27 303/week @ 2024-11-03 261/week @ 2024-11-10 420/week @ 2024-11-17

1,130 downloads per month
Used in 4 crates

MIT/Apache

12KB
167 lines

casual

Crates.io Version Docs.rs Latest Build Status

Simple crate for parsing user input.

Getting started

Add the following dependency to your Cargo.toml.

[dependencies]
casual = "0.2"

Usage

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!");
}

License

Licensed under either of

at your option.

No runtime deps