Skip to main content

Crate tinyinput

Crate tinyinput 

Source
Expand description

§tinyinput

tinyinput is a tiny, dependency-free helper crate for reading and parsing user input from stdin in Rust.

§Why tinyinput?

Taking user input in Rust typically involves reading from stdin, trimming the input, and manually parsing it into the desired type. While this is explicit and correct, it often leads to repetitive boilerplate in small programs, examples, and learning projects.

tinyinput provides a simpler alternative by leveraging Rust’s compile-time type inference. The target type is inferred from the assignment context, so callers usually do not need to specify the type explicitly at the call site.

§Example: reading user input in Rust

let count: i32 = tinyinput::read("Enter count: ").unwrap();
let ratio: f64 = tinyinput::read("Enter ratio: ").unwrap_or_default();
let name: String = tinyinput::read("Enter name: ").unwrap();

§What this crate is (and is not)

  • ✔ Minimal and lightweight

  • ✔ No macros

  • ✔ No global state

  • ✔ No hidden panics

  • ✔ No dependencies

  • ✔ Suitable for small CLI tools, scripts, and learning Rust

  • ✘ Not a replacement for full command-line parsers like clap

  • ✘ Not intended for complex argument handling

§Design philosophy

tinyinput focuses on doing one thing well: reading a single line of input from standard input and parsing it into a Rust type using FromStr. Error handling is explicit and returned to the caller, allowing each program to decide how to handle invalid input.

Enums§

ReadError
Errors that can occur while reading or parsing user input.

Functions§

read
Read a line of input from standard input and parse it into type T.