mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 06:12:40 +00:00
feat(derive): Accept Box/Arc wrapped types
This commit is contained in:
parent
7353b2be34
commit
f043f57559
1 changed files with 22 additions and 0 deletions
|
@ -2215,6 +2215,28 @@ impl ValueParserFactory for u64 {
|
|||
RangedU64ValueParser::new()
|
||||
}
|
||||
}
|
||||
impl<T> ValueParserFactory for Box<T>
|
||||
where
|
||||
T: ValueParserFactory,
|
||||
<T as ValueParserFactory>::Parser: TypedValueParser<Value = T>,
|
||||
T: Send + Sync + Clone,
|
||||
{
|
||||
type Parser = MapValueParser<<T as ValueParserFactory>::Parser, fn(T) -> Box<T>>;
|
||||
fn value_parser() -> Self::Parser {
|
||||
T::value_parser().map(Box::new)
|
||||
}
|
||||
}
|
||||
impl<T> ValueParserFactory for std::sync::Arc<T>
|
||||
where
|
||||
T: ValueParserFactory,
|
||||
<T as ValueParserFactory>::Parser: TypedValueParser<Value = T>,
|
||||
T: Send + Sync + Clone,
|
||||
{
|
||||
type Parser = MapValueParser<<T as ValueParserFactory>::Parser, fn(T) -> std::sync::Arc<T>>;
|
||||
fn value_parser() -> Self::Parser {
|
||||
T::value_parser().map(std::sync::Arc::new)
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Reference in a new issue