askit 0.2.0

A simple and semantic library to ask for user input in CLI applications. Type-safe parsing, defaults and retries.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use crate::prompt_mod::error::Error;
use std::str::FromStr;

pub fn parse_as<T>(s: &str) -> Result<T, Error>
where
    T: FromStr,
    T::Err: std::fmt::Display,
{
    T::from_str(s).map_err(|e| Error::Parse {
        ty: std::any::type_name::<T>(),
        cause: e.to_string(),
    })
}