RustInput 0.2.0

A fluent CLI input crate for Rust, supporting all integer, float, bool, and string types; easier to use unlike the standard std::io
Documentation
  • Coverage
  • 57.14%
    8 out of 14 items documented0 out of 11 items with examples
  • Size
  • Source code size: 7.98 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.41 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • LilCloudCoder/RustInput
    1 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • LilCloudCoder

Fluent Input 🦀

Simple, fluent input for Rust CLI apps — easier to use than the standard std::io.


Install

Add to your project's Cargo.toml (example):

[dependencies]
rustinput = { git = "https://github.com/lilcloudcoder/RustInput" }

Note: inside this repository the crate name is RustInput (PascalCase). In external projects, Cargo will expose it as rustinput (snake_case).

Quick start

// In external projects
use rustinput::input; // or: use rustinput::Input;

fn main() {
    let a: i32 = input("Enter i32: ").int();
    let b: f64 = input("Enter f64: ").float();
    let name = input("Enter name: ").string();
    let agree = input("Agree? ").bool();

    println!("{a} {b} {name} {agree}");
}

Inside this repo's examples/binary use:

use RustInput::input;

Features

  • Ergonomic prompts: input("Your age: ").int::<i32>()
  • All integer and float types supported via FromStr
  • Strings and booleans with common aliases (y/yes/true/1, n/no/false/0)
  • New helpers:
    • char() — read a single character
    • optional::<T>() -> Option<T> — Enter to skip
    • default::<T>(value) -> T — Enter to accept default
    • choices(&["light", "dark"]) -> String — restrict to allowed values (case-insensitive)

API cheatsheet

use rustinput::input;

let i: i64 = input("i64: ").int();
let u: usize = input("usize: ").int();
let f: f32 = input("f32: ").float();
let s: String = input("name: ").string();
let b: bool = input("ok? ").bool();
let c: char = input("initial: ").char();
let maybe_n: Option<i32> = input("number (Enter to skip): ").optional();
let tries: u32 = input("tries (default 3): ").default(3);
let theme: String = input("theme [light/dark]: ").choices(&["light", "dark"]);

Types supported

  • Integers: all signed/unsigned (i8..i128, u8..u128, isize, usize)
  • Floats: f32, f64
  • Bool, String, Char