Skip to content

Commit

Permalink
feat(derive): Accept Boxed Str/OsStr/Path
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 5, 2023
1 parent 916c8d9 commit a50e32c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions clap_builder/src/builder/value_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2137,18 +2137,38 @@ impl ValueParserFactory for String {
ValueParser::string() // Default `clap_derive` to optimized implementation
}
}
impl ValueParserFactory for Box<str> {
type Parser = MapValueParser<StringValueParser, fn(String) -> Box<str>>;
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<std::ffi::OsStr> {
type Parser =
MapValueParser<OsStringValueParser, fn(std::ffi::OsString) -> Box<std::ffi::OsStr>>;
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<std::path::Path> {
type Parser =
MapValueParser<PathBufValueParser, fn(std::path::PathBuf) -> Box<std::path::Path>>;
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 {
Expand Down

0 comments on commit a50e32c

Please sign in to comment.