askit/lib.rs
1//! askit: a simple and ergonomic CLI input library.
2//!
3//! Quickstart com `Result`:
4//! ```no_run
5//! use askit::prompt;
6//!
7//! fn sample() -> Result<(), askit::Error> {
8//! let name: String = prompt("Name: ").get()?;
9//! let age: u8 = prompt("Age [18]: ").default("18").retries(2).get()?;
10//! println!("Hello, {} ({}).", name, age);
11//! Ok(())
12//! }
13//! ```
14//!
15//! Quickstart com macro `input!` (return only String):
16//! ```no_run
17//! use askit::input;
18//!
19//! let name = input!("Name: ");
20//! println!("Hello, {name}");
21//! ```
22
23mod macros;
24pub mod prompt_mod;
25
26pub use prompt_mod::{Error, Prompt, TypedPrompt, Validator, prompt};
27
28/// Helper `Result<T, Error>` → forçar unwrap com panic elegante.
29pub trait ForceOk<T> {
30 fn force(self) -> T;
31}
32
33impl<T> ForceOk<T> for Result<T, Error> {
34 fn force(self) -> T {
35 match self {
36 Ok(v) => v,
37 Err(e) => panic!("askit error: {e}"),
38 }
39 }
40}