#input #error-handling #terminal #custom-messages #recoverable-errors

inputparser

Terminal inputs made psuedo code like simple, like Python like simple ...... probably xD

13 releases

0.1.72 Jul 29, 2020
0.1.71 Jul 28, 2020

#665 in Command-line interface

Download history 3/week @ 2023-11-04 1/week @ 2023-11-11 16/week @ 2023-11-18 33/week @ 2023-11-25 30/week @ 2023-12-02 15/week @ 2023-12-09 30/week @ 2023-12-23 13/week @ 2024-01-06 15/week @ 2024-01-20 30/week @ 2024-01-27 15/week @ 2024-02-03 50/week @ 2024-02-10 262/week @ 2024-02-17

357 downloads per month

MIT license

6KB
62 lines

crates.io version Crates.io Downloads crates.io license Discord image

inputparser

Note: Thanks to @Restioson, @ThatsNoMoon and @kangalioo for helping me write the code

Now Rust inputs are almost as simple as Python

Terminal inputs are now easier than ever. Replacing over 5 lines of codes with just 1 function.

Supports all formats that FromStr Supports

Instead of

let mut var: String = String::new();
io::stdin().read_line(&mut var).unwrap();
let var: i32 = var.trim().parse().unwrap();

why not

let var: i32 = input(Def);

and it doesn't panic when wrong format is entered (when default arg [Def]).

Or you can choose to make it panic too.

Usage

[dependencies]
inputparser = "0.1"

Example

extern crate inputparser;
use inputparsertest::{input, input_w_msg, inputfn, ErHandle::*};

fn main() {
    //for Default continue message "Input not supported" when Err
    let i: i32 = input(Def);

    //for custom panic message when Err
    let j: f64 = input(Pnc("Panic Message"));

    //for custom continue message when Err
    let k: u128 = input(Msg("Continue Message"));

    //for custom loop message and continue/error message
    let l: isize = input_w_msg("Enter the number",Msg("Please enter valid number"));

    //for more Rust way for handling the error
    let m: usize = inputfn(|| /*use panic if required*/ println!("Continue Error Message"));
 
    println!("{} {} {} {} {}", i, j, k, l, m);
}

No runtime deps