| Crates.io | el_roi |
| lib.rs | el_roi |
| version | 0.1.0 |
| created_at | 2025-06-14 11:03:52.840434+00 |
| updated_at | 2025-06-14 11:03:52.840434+00 |
| description | A crate to simplify reading user input |
| homepage | |
| repository | https://github.com/PhantomXero/el_roi.git |
| max_upload_size | |
| id | 1712273 |
| size | 14,052 |
El Roi is a Rust library that simplifies reading user input from the command line. It provides ergonomic, prompt-driven functions for reading strings, integers, floats, booleans, characters, and vectors of these types. The crate is designed for usability, clarity, and testability.
El Roi abstracts away the repetitive patterns of reading and parsing user input, allowing developers to easily and safely gather data from users in CLI applications.
i32), floating-point numbers (f64), booleans, characters, and vectors of these typesAdd El Roi as a dependency in your project's Cargo.toml:
el_roi = "0.1.0"
Or, if using a local path during development:
el_roi = { path = "../el_roi" }
Import and use the utility functions in your Rust code. Each function takes a prompt string, which is displayed to the user before reading input.
use el_roi::{read_string, read_int, read_float, read_bool, read_char, read_int_vec, read_float_vec, read_string_vec};
fn main() {
let name = read_string("Enter your name");
let age = read_int("Enter your age");
let pi = read_float("Enter the value of pi");
let likes_rust = read_bool("Do you like Rust? (true/false)");
let initial = read_char("Enter the first letter of your name");
let numbers = read_int_vec("Enter some numbers separated by spaces");
let floats = read_float_vec("Enter some floats separated by spaces");
let words = read_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);
}
read_string(prompt: &str) -> String — Read a string from the userread_int(prompt: &str) -> i32 — Read an integerread_float(prompt: &str) -> f64 — Read a floating-point numberread_bool(prompt: &str) -> bool — Read a boolean (true/false, yes/no, 1/0)read_char(prompt: &str) -> char — Read a single characterread_int_vec(prompt: &str) -> Vec<i32> — Read a vector of integers (space-separated)read_float_vec(prompt: &str) -> Vec<f64> — Read a vector of floats (space-separated)read_string_vec(prompt: &str) -> Vec<String> — Read a vector of strings (space-separated)use el_roi::{read_string, read_int, read_bool};
fn main() {
let username = read_string("Username");
let age = read_int("Age");
let is_admin = read_bool("Are you an admin? (yes/no)");
println!("User: {}, Age: {}, Admin: {}", username, age, is_admin);
}
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.
This project is licensed under the MIT License. See the LICENSE file for details.