Skip to content

Commit

Permalink
feat(derive): Accept Box/Arc wrapped types
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 5, 2023
1 parent 7353b2b commit f043f57
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions clap_builder/src/builder/value_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit f043f57

Please sign in to comment.