use std::marker::PhantomData; use std::str::FromStr; use rpc_toolkit::clap; use rpc_toolkit::clap::builder::TypedValueParser; pub struct FromStrParser(PhantomData); impl FromStrParser { pub fn new() -> Self { Self(PhantomData) } } impl Clone for FromStrParser { fn clone(&self) -> Self { Self(PhantomData) } } impl TypedValueParser for FromStrParser where T: FromStr + Clone + Send + Sync + 'static, T::Err: std::fmt::Display, { type Value = T; fn parse_ref( &self, _: &clap::Command, _: Option<&clap::Arg>, value: &std::ffi::OsStr, ) -> Result { value .to_string_lossy() .parse() .map_err(|e| clap::Error::raw(clap::error::ErrorKind::ValueValidation, e)) } }