ask_input โจ๏ธ
A micro-library for keyboard input in Rust. No extra code โ just input and get values!
๐ Description
ask_input is a tiny wrapper over Rust's standard I/O. One function. All types. Rust figures out the type automatically.
Features:
- ๐ฏ One function for everything
- ๐ง Smart type detection
- ๐ก๏ธ Automatic stdout flushing to prevent prompt-freezing
- โก Zero dependencies
โ๏ธ Installation
Add to your Cargo.toml:
[]
= "0.3.0"
๐งช Examples
Basic usage with expect
use input;
With match for graceful error handling
use input;
With unwrap_or for default values
use input;
๐ฆ Functions
input::<T>()โ Input any type (i32, f64, String, etc.)
๐ Supported Types
| Type | Example | Notes |
|---|---|---|
i32 |
42 |
Leading/trailing whitespace trimmed |
f64 |
3.14 |
Leading/trailing whitespace trimmed |
String |
Hello |
Whitespace preserved (only newline removed) |
bool |
true |
Case-sensitive, whitespace trimmed |
i64, u32... |
Any numeric | Whitespace trimmed |
โ ๏ธ Breaking Changes (v0.1.0 โ v0.2.0)
int_input()โinput::<i32>()float_input()โinput::<f64>()str_input()โinput::<String>()- Now returns
Resultinstead of panicking
๐ Changelog (v0.2.0 โ v0.3.0)
- Added automatic
io::stdout().flush()before reading input. This guarantees thatprint!prompts appear on screen instantly, fixing terminal output freezing. - Updated all inline documentation to English.
๐ค Author
- FelineFantasy
- License: MIT