Skip to content

Latest commit

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

ask_input ⌨️

Rust VersionLicenseCrates.iodocs.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;fnmain(){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;fnmain(){println!("Enter your age:");let age:i32 = matchinput(){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;fnmain(){// If input fails, use 0.0 as defaultlet price:f64 = input().unwrap_or(0.0);println!("Price: {}", price);}

📦 Functions

  • input::<T>() — Input any type (i32, f64, String, etc.)

📋 Supported Types

TypeExampleNotes
i3242Leading/trailing whitespace trimmed
f643.14Leading/trailing whitespace trimmed
StringHelloWhitespace preserved (only newline removed)
booltrueCase-sensitive, whitespace trimmed
i64, u32...Any numericWhitespace 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

About

Micro-library for simple keyboard input in Rust

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages