read_input 0.1.1

A simple tool that asks for data until the data is valid.
Documentation

Read Input

A simple tool that asks for data until the data is valid.

pipeline status License Latest version Latest Docs downloads-badge

Help

If you run into any issues or need help with using read_input in your project please email incoming+efunb/read_input@incoming.gitlab.com

Why you need it.

When writing simple programs you will often need to take input from the user. If the user inputs invalid information the program needs to try asking them again. Having to make this loop distracts from the useful logic in your program.

Read input attempts to make it easy to get input from the user without having to think about converting types.

How to use.

Add

read_input = "0.1.1"

to your cargo.toml under [dependencies] and add

extern crate read_input;

use read_input::*;

to your main file.

You can get input with.

let input = Type::simple_input();

Where Type is the type you want. Currently the types you can use include i8, u8, i16, u16, f32, i32, u32, f64, i64, u64, i128, u128 and String.

So if you want a valid unsigned 32bit value you could write.

let input = u32::simple_input();

You can also add your own checks to ensure the value meets your criteria. If you want a signed 16bit value between 4 and 9 you could write.

let input = i16::valid_input(|x| 4 < *x && *x < 9);

The read_input associated function allows for custom error messages and validation at the same time.

Docs

API Documentation

Warning

If you are viewing this from GitHub then this is a read only copy. Please contribute to the GitLab copy here.