Skip to main content

Crate el_roi

Crate el_roi 

Source
Expand description

§El Roi

Crates.io Docs.rs License: MIT

el_roi is a Rust crate that simplifies reading user input from the command line. It provides ergonomic functions for reading strings, integers, floats, booleans, characters, and vectors of these types, with both prompted (prompt_*) and unprompted APIs for stream-style input.

§Features

  • Prompted and unprompted input variants for each supported type
  • Read integers (i32), floats (f64), booleans, characters, and vectors of these types
  • Testable design: all parsing logic is separated for easy unit testing
  • Prompted reads re-prompt on invalid input and show an example of valid input

§Usage

Add to your Cargo.toml:

el_roi = "0.1.0"

§Example

use el_roi::{
    prompt_bool, prompt_char, prompt_float, prompt_float_vec, prompt_int, prompt_int_vec,
    prompt_string, prompt_string_vec,
};

fn main() {
    let name = prompt_string("Enter your name");
    let age = prompt_int("Enter your age");
    let pi = prompt_float("Enter the value of pi");
    let likes_rust = prompt_bool("Do you like Rust? (true/false)");
    let initial = prompt_char("Enter the first letter of your name");
    let numbers = prompt_int_vec("Enter some numbers separated by spaces");
    let floats = prompt_float_vec("Enter some floats separated by spaces");
    let words = prompt_string_vec("Enter some words separated by spaces");
    println!("Hello, {}! Age: {} Pi: {} Likes Rust: {} Initial: {} Numbers: {:?} Floats: {:?} Words: {:?}",
        name, age, pi, likes_rust, initial, numbers, floats, words);
}

§Testing

All parsing logic is separated into private helper functions, making it easy to test with in-memory buffers. See the crate’s tests for examples.

§License

MIT

Functions§

prompt_bool
Function to get a boolean input from the user input with a prompt
prompt_char
Function to get a character input from the user input with a prompt
prompt_float
Function to get a float(f64) input from the user input with a prompt
prompt_float_vec
Function to get a vector of floats(f64) input from the user input with a prompt
prompt_int
Function to get an integer(i32) input from the user input with a prompt
prompt_int_vec
Function to get a vector of integers(i32) input from the user input with a prompt
prompt_string
Public API: user-facing functions (read from stdin) Function to get String input from the user input with a prompt
prompt_string_vec
Function to get a vector of strings input from the user input with a prompt
read_bool
Function to get a boolean input from the user input without a prompt
read_char
Function to get a character input from the user input without a prompt
read_float
Function to get a float(f64) input from the user input without a prompt
read_float_vec
Function to get a vector of floats(f64) input from the user input without a prompt
read_int
Function to get an integer(i32) input from the user input without a prompt
read_int_vec
Function to get a vector of integers(i32) input from the user input without a prompt
read_string
Function to get String input from the user input without a prompt
read_string_vec
Function to get a vector of strings input from the user input without a prompt