From a50e32c1357b9a73da6c7b2d4506dd4be8f3420f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 5 Jul 2023 10:03:52 -0500 Subject: [PATCH] feat(derive): Accept Boxed Str/OsStr/Path --- clap_builder/src/builder/value_parser.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/clap_builder/src/builder/value_parser.rs b/clap_builder/src/builder/value_parser.rs index 2e43d98f652..b1540e08a10 100644 --- a/clap_builder/src/builder/value_parser.rs +++ b/clap_builder/src/builder/value_parser.rs @@ -2137,18 +2137,38 @@ impl ValueParserFactory for String { ValueParser::string() // Default `clap_derive` to optimized implementation } } +impl ValueParserFactory for Box { + type Parser = MapValueParser Box>; + fn value_parser() -> Self::Parser { + StringValueParser::new().map(String::into_boxed_str) + } +} impl ValueParserFactory for std::ffi::OsString { type Parser = ValueParser; fn value_parser() -> Self::Parser { ValueParser::os_string() // Default `clap_derive` to optimized implementation } } +impl ValueParserFactory for Box { + type Parser = + MapValueParser Box>; + fn value_parser() -> Self::Parser { + OsStringValueParser::new().map(std::ffi::OsString::into_boxed_os_str) + } +} impl ValueParserFactory for std::path::PathBuf { type Parser = ValueParser; fn value_parser() -> Self::Parser { ValueParser::path_buf() // Default `clap_derive` to optimized implementation } } +impl ValueParserFactory for Box { + type Parser = + MapValueParser Box>; + fn value_parser() -> Self::Parser { + PathBufValueParser::new().map(std::path::PathBuf::into_boxed_path) + } +} impl ValueParserFactory for bool { type Parser = ValueParser; fn value_parser() -> Self::Parser {