ask_input 0.3.0

Simple input library
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented2 out of 2 items with examples
  • Size
  • Source code size: 6.48 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 242.59 kB This is the summed size of all files generated by rustdoc for all configured targets
  • ร˜ build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • FelineFantasy/ask_input
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • FelineFantasy

ask_input โŒจ๏ธ

Rust Version License docs.rs

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:

[dependencies]

ask_input = "0.3.0"

๐Ÿงช Examples

Basic usage with expect

use ask_input::input;

fn main() {
    let age: i32 = input().expect("Failed to read age");
    let price: f64 = input().expect("Failed to read price");
    let name: String = input().expect("Failed to read name");
    
    println!("Age: {}, Price: {}, Name: {}", age, price, name);
}

With match for graceful error handling

use ask_input::input;

fn main() {
    println!("Enter your age:");
    
    let age: i32 = match input() {
        Ok(num) => num,
        Err(_) => {
            println!("Invalid input! Using default age 18.");
            18
        }
    };
    
    println!("Your age: {}", age);
}

With unwrap_or for default values

use ask_input::input;

fn main() {
    // If input fails, use 0.0 as default
    let price: f64 = input().unwrap_or(0.0);
    println!("Price: {}", price);
}

๐Ÿ“ฆ 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 Result instead of panicking

๐Ÿ”„ Changelog (v0.2.0 โ†’ v0.3.0)

  • Added automatic io::stdout().flush() before reading input. This guarantees that print! prompts appear on screen instantly, fixing terminal output freezing.
  • Updated all inline documentation to English.

๐Ÿ‘ค Author

  • FelineFantasy
  • License: MIT