#input-validation #input #error-message #validation #array #simple

yanked painless_input

A simple input library with support for array input, validation, and pretty error messages

4 releases

0.1.4 Sep 14, 2023
0.1.3 Sep 8, 2023
0.1.2 Sep 7, 2023
0.1.1 Sep 7, 2023
0.1.0 Sep 7, 2023

#28 in #input-validation

24 downloads per month

MIT license

30KB
418 lines

Painless Input

This is an easy to use input library crate. It automatically handles parsing errors and data validation with a simple syntax and good looking error messages.

Error message:

Error

Array input:

Array

Multiselect input:

Multiselect

Select input:

Select

Usage

Normal input:

use painless_input::input;

fn main() {
    let num: u8 = input("Enter a number: ");
    println!();
}

Array input:

use painless_input::input_array;

fn main() {
    let nums: Vec<u8> = input_array("Enter a list of numbers: ");
    println!();
}

Data validation:

use painless_input::input_with_validation;

fn main() {
    let validated_num = input_with_validation::<u8>("Enter a number between 0 and 10: ", Box::new(|value| {
        if value < 0 || value > 10 {
            Err("Number must be between 0 and 10")
        } else {
            Ok(())
        }
    }));
    println!();
}

Features

  • Array input
  • Builtin data validation with custom messages
  • Pretty error messages
  • Cross platform

Dependencies

Dependencies

~0.8–5MB
~20K SLoC