| Crates.io | askit |
| lib.rs | askit |
| version | 0.2.0 |
| created_at | 2025-08-19 19:54:38.831812+00 |
| updated_at | 2025-08-20 22:14:44.888406+00 |
| description | A simple and semantic library to ask for user input in CLI applications. Type-safe parsing, defaults and retries. |
| homepage | |
| repository | https://github.com/Bruno-Gomes-QA/askit |
| max_upload_size | |
| id | 1802368 |
| size | 26,643 |
askit is a simple and semantic Rust library to handle interactive CLI
prompts, inspired by Python’s input.
It provides a pythonic input! macro (always returns String) and
an advanced Prompt builder API for developers who need retries,
defaults, type safety, and validation.
input! macro: Python-like, minimal, always returns String.Prompt builder: Advanced API for typed input, defaults, retries, and validation.Prompt, you can directly parse into Rust types.Add the following to your Cargo.toml:
[dependencies]
askit = "0.2.0"
use askit::input;
fn main() {
let name = input!("Your name: ");
println!("Hello, {name}");
// Parsing is your responsibility (just like Python’s int(input()))
let age: u8 = input!("Age: ").parse().unwrap_or(18);
println!("Age: {age}");
}
String.Prompt.Examples:
use askit::input;
fn main() {
let city = input!("City: ");
println!("City = {city}");
let number: i32 = input!("Number: ").parse().unwrap();
println!("Number = {number}");
}
The Prompt builder gives you more control:
use askit::prompt;
fn main() -> Result<(), askit::Error> {
let threads: usize = prompt("Threads: ")
.to::<usize>() // type-safe parsing
.default_val(4) // default if empty input
.retries(2) // allow multiple attempts
.validate(|v| *v > 0) // custom validation
.message("Threads must be > 0")// custom error message
.get()?; // final input
println!("threads = {threads}");
Ok(())
}
.default("str") → provide a string default..to::<T>() → switch to typed input (i32, f64, custom types, etc)..default_val(T) → set a typed default..retries(n) → allow multiple attempts..trim(true/false) → control whitespace trimming..validate(|v| ...) → attach a custom validator..message("...") → custom validation error message..get() → read input and return Result<T, Error>.All fallible operations return Result<T, askit::Error>.
Errors include:
Io → I/O error when reading/writing.Parse → Failed to parse into the requested type.EmptyNotAllowed → Input was empty and no default was provided.RetriesExceeded → Too many failed attempts.Validation → Custom validation failed.cargo run --example input_showcases
cargo test
MIT License.