asker

Crates.ioasker
lib.rsasker
version0.3.0
sourcesrc
created_at2022-02-28 20:44:28.003442
updated_at2022-03-05 20:00:37.926547
descriptionSmoothly get and check user input
homepage
repositoryhttps://github.com/Octalbyte/asker
max_upload_size
id541162
size16,437
(Octalbyte)

documentation

README

asker

Input prompt, for Rust

Install

[dependencies]
asker = "0.3.0"

Usage

For a complete guide, check GUIDE.md and examples

    use asker::ask::Regex;
    use asker::ask;
    use asker::ask::FieldSet;

    // This example demonstrates basic usage, and main features

    fn main(){
        let fields: FieldSet = vec![
            ("email", vec![""], Some(Regex::new(r".*@gmail.com").unwrap())),
            ("username", vec!["req: Must be only lower-case letters", "default:uglyoctopus"], Some(Regex::new(r"^\p{Ll}+$").unwrap())),
            ("Are you logged?", vec!["isbool", "id:islogged"], None),
            ("password", vec!["hidden", "confirm"], None),
            ("In which year were you born", vec!["id:birth","default:1999"], Some(Regex::new(r"^\p{Nd}+$").unwrap())),
            ("Do you agree to the Terms of Service?", vec!["id:terms", "isbool", "default:true"], None),
        ];
        let (mut f, mut b) = ask::ask(fields);

        println!("\nString results");

        for (index, value) in f.iter_mut() {
            println!("{} --> {}", index, value);
        }

        println!("\nBool results");

        for (index, value) in b.iter_mut() {
            println!("{} --> {}", index, value);
        }

        println!("");
    }

Output:

image

Commit count: 63

cargo fmt