El Roi Project
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.
Purpose
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.
Features
- Prompt the user with a custom question for each input
- Read integers (
i32), floating-point numbers (f64), booleans, characters, and vectors of these types - Consistent, easy-to-use API for all supported types
- Testable design: parsing logic is separated for easy unit testing
Installation
Add El Roi as a dependency in your project's Cargo.toml:
= "0.1.0"
Or, if using a local path during development:
= { = "../el_roi" }
Usage
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.
Basic Example
use ;
Function Reference
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)
Example: Reading Multiple Types
use ;
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
This project is licensed under the MIT License. See the LICENSE file for details.