2 releases
0.1.1 | Apr 26, 2019 |
---|---|
0.1.0 | Apr 26, 2019 |
#6 in #gender
10KB
116 lines
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.
lib.rs
:
Getting data from a human, from stdin.
This library provides methods for getting information from a human. They all work on buffered lines of input (this is how terminals work unless you put them in a different mode). They are useful for building simple interactive command line apps (for example how pacman gets confirmantion during a system upgrade on arch linux). They are also useful for learning, when you want to be able to get data easily.