read-human

Crates.ioread-human
lib.rsread-human
version0.1.1
sourcesrc
created_at2019-04-26 13:41:08.23157
updated_at2019-04-26 13:46:03.388668
descriptionRead things from a human on the command line.
homepage
repositoryhttps://github.com/derekdreery/read-human
max_upload_size
id130320
size11,107
Richard Dodd (derekdreery)

documentation

README

Get input from a human via. the command line.

Examples

use std::io;

#[derive(Debug)]
pub enum Gender {
    Male,
    Female,
    Other,
}

#[derive(Debug)]
pub struct Person {
    name: String,
    age: u16,
    gender: Gender,
}

fn main() -> Result<(), io::Error> {
    let name = read_human::read_string_nonempty("What is your name")?;
    let age = read_human::read_custom_nonempty("What is your age")?;
    let gender =
        match read_human::read_choice("What is your gender", &["male", "female", "other"], None)? {
            0 => Gender::Male,
            1 => Gender::Female,
            2 => Gender::Other,
            _ => unreachable!(),
        };
    let person = Person { name, age, gender };
    println!("{:?}", person);
    Ok(())
}

See examples/simple.rs for a slightly more involved example.

Commit count: 6

cargo fmt