feat(parsr): Expose all built-in TypedValueParsers

This makes life easier for people, whether they want a geneirc
`NonEmpty<impl TypedValueParser>` or a `PathBufExists(PathBuf)`.
This commit is contained in:
Ed Page 2022-05-16 17:16:39 -05:00
parent 2ffa38f9f5
commit 6b0306df9e
2 changed files with 20 additions and 4 deletions

View file

@ -34,10 +34,14 @@ pub use value_parser::via_prelude;
pub use value_parser::AnyValueParser; pub use value_parser::AnyValueParser;
pub use value_parser::ArgEnumValueParser; pub use value_parser::ArgEnumValueParser;
pub use value_parser::AutoValueParser; pub use value_parser::AutoValueParser;
pub use value_parser::BoolValueParser;
pub use value_parser::BoolishValueParser; pub use value_parser::BoolishValueParser;
pub use value_parser::FalseyValueParser; pub use value_parser::FalseyValueParser;
pub use value_parser::NonEmptyStringValueParser; pub use value_parser::NonEmptyStringValueParser;
pub use value_parser::OsStringValueParser;
pub use value_parser::PathBufValueParser;
pub use value_parser::PossibleValuesParser; pub use value_parser::PossibleValuesParser;
pub use value_parser::StringValueParser;
pub use value_parser::TypedValueParser; pub use value_parser::TypedValueParser;
pub use value_parser::ValueParser; pub use value_parser::ValueParser;

View file

@ -404,8 +404,11 @@ where
} }
} }
/// Implementation for [`ValueParser::string`]
///
/// Useful for composing new [`TypedValueParser`]s
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
struct StringValueParser; pub struct StringValueParser;
impl TypedValueParser for StringValueParser { impl TypedValueParser for StringValueParser {
type Value = String; type Value = String;
@ -435,8 +438,11 @@ impl TypedValueParser for StringValueParser {
} }
} }
/// Implementation for [`ValueParser::os_string`]
///
/// Useful for composing new [`TypedValueParser`]s
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
struct OsStringValueParser; pub struct OsStringValueParser;
impl TypedValueParser for OsStringValueParser { impl TypedValueParser for OsStringValueParser {
type Value = std::ffi::OsString; type Value = std::ffi::OsString;
@ -460,8 +466,11 @@ impl TypedValueParser for OsStringValueParser {
} }
} }
/// Implementation for [`ValueParser::path_buf`]
///
/// Useful for composing new [`TypedValueParser`]s
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
struct PathBufValueParser; pub struct PathBufValueParser;
impl TypedValueParser for PathBufValueParser { impl TypedValueParser for PathBufValueParser {
type Value = std::path::PathBuf; type Value = std::path::PathBuf;
@ -730,8 +739,11 @@ where
} }
} }
/// Implementation for [`ValueParser::bool`]
///
/// Useful for composing new [`TypedValueParser`]s
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
struct BoolValueParser; pub struct BoolValueParser;
impl BoolValueParser { impl BoolValueParser {
fn possible_values() -> impl Iterator<Item = crate::PossibleValue<'static>> { fn possible_values() -> impl Iterator<Item = crate::PossibleValue<'static>> {