askit 0.2.0

A simple and semantic library to ask for user input in CLI applications. Type-safe parsing, defaults and retries.
Documentation
use std::io;

#[derive(Debug)]
pub enum Error {
    Io(io::Error),
    Parse { ty: &'static str, cause: String },
    EmptyNotAllowed,
    RetriesExceeded,
    Validation(String),
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Error::Io(e) => write!(f, "I/O error: {e}"),
            Error::Parse { ty, cause } => write!(f, "Failed to parse as {ty}: {cause}"),
            Error::EmptyNotAllowed => write!(f, "Empty input (no default provided)"),
            Error::RetriesExceeded => write!(f, "Maximum retry attempts exceeded"),
            Error::Validation(msg) => write!(f, "Validation failed: {msg}"),
        }
    }
}

impl std::error::Error for Error {}
impl From<io::Error> for Error {
    fn from(e: io::Error) -> Self {
        Error::Io(e)
    }
}