Expand description
§El Roi
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