el_roi 0.1.0

A crate to simplify reading user input
Documentation
  • Coverage
  • 100%
    9 out of 9 items documented1 out of 9 items with examples
  • Size
  • Source code size: 13.58 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.31 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • PhantomXero/el_roi
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • PhantomXero

El Roi Project

Crates.io Docs.rs License: MIT

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:

el_roi = "0.1.0"

Or, if using a local path during development:

el_roi = { path = "../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 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);
}

Function Reference

  • read_string(prompt: &str) -> String — Read a string from the user
  • read_int(prompt: &str) -> i32 — Read an integer
  • read_float(prompt: &str) -> f64 — Read a floating-point number
  • read_bool(prompt: &str) -> bool — Read a boolean (true/false, yes/no, 1/0)
  • read_char(prompt: &str) -> char — Read a single character
  • read_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 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);
}

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.