casual 0.2.0

Simple crate for parsing user input.
Documentation
  • Coverage
  • 92.86%
    13 out of 14 items documented7 out of 13 items with examples
  • Size
  • Source code size: 25.93 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.63 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • rossmacarthur/casual
    2 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • rossmacarthur

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.