Skip to main content

## ValueParserFactory

# Trait ValueParserFactory

Source

    pub trait ValueParserFactory {
        type Parser;

        // Required method
        fn value_parser() -> Self::Parser;
    }

Expand description

Register a type with `value_parser!`

## §Example

    #[derive(Copy, Clone, Debug)]
    pub struct Custom(u32);

    impl clap::builder::ValueParserFactory for Custom {
        type Parser = CustomValueParser;
        fn value_parser() -> Self::Parser {
            CustomValueParser
        }
    }

    #[derive(Clone, Debug)]
    pub struct CustomValueParser;
    impl clap::builder::TypedValueParser for CustomValueParser {
        type Value = Custom;

        fn parse_ref(
            &self,
            cmd: &clap::Command,
            arg: Option<&clap::Arg>,
            value: &std::ffi::OsStr,
        ) -> Result<Self::Value, clap::Error> {
            let inner = clap::value_parser!(u32);
            let val = inner.parse_ref(cmd, arg, value)?;
            Ok(Custom(val))
        }
    }

    let parser: CustomValueParser = clap::value_parser!(Custom);

## Required Associated Types§

Source

#### type Parser

Generated parser, usually `ValueParser`.

It should at least be a type that supports `Into<ValueParser>`. A non-`ValueParser` type allows the caller to do further initialization on the parser.

## Required Methods§

Source

#### fn value_parser() -> Self::Parser

Create the specified `Self::Parser`

## Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

## Implementations on Foreign Types§

Source§

### impl ValueParserFactory for Box<OsStr>

Source§

#### type Parser = MapValueParser<OsStringValueParser, fn(OsString) -> Box<OsStr>>

Source§

#### fn value_parser() -> <Box<OsStr> as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for Box<Path>

Source§

#### type Parser = MapValueParser<PathBufValueParser, fn(PathBuf) -> Box<Path>>

Source§

#### fn value_parser() -> <Box<Path> as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for Box<str>

Source§

#### type Parser = MapValueParser<StringValueParser, fn(String) -> Box<str>>

Source§

#### fn value_parser() -> <Box<str> as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for OsString

Source§

#### type Parser = ValueParser

Source§

#### fn value_parser() -> <OsString as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for PathBuf

Source§

#### type Parser = ValueParser

Source§

#### fn value_parser() -> <PathBuf as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for String

Source§

#### type Parser = ValueParser

Source§

#### fn value_parser() -> <String as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for bool

Source§

#### type Parser = ValueParser

Source§

#### fn value_parser() -> <bool as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for i8

Source§

#### type Parser = RangedI64ValueParser<i8>

Source§

#### fn value_parser() -> <i8 as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for i16

Source§

#### type Parser = RangedI64ValueParser<i16>

Source§

#### fn value_parser() -> <i16 as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for i32

Source§

#### type Parser = RangedI64ValueParser<i32>

Source§

#### fn value_parser() -> <i32 as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for i64

Source§

#### type Parser = RangedI64ValueParser

Source§

#### fn value_parser() -> <i64 as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for u8

Source§

#### type Parser = RangedI64ValueParser<u8>

Source§

#### fn value_parser() -> <u8 as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for u16

Source§

#### type Parser = RangedI64ValueParser<u16>

Source§

#### fn value_parser() -> <u16 as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for u32

Source§

#### type Parser = RangedI64ValueParser<u32>

Source§

#### fn value_parser() -> <u32 as ValueParserFactory>::Parser

Source§

### impl ValueParserFactory for u64

Source§

#### type Parser = RangedU64ValueParser

Source§

#### fn value_parser() -> <u64 as ValueParserFactory>::Parser

Source§

### impl<T> ValueParserFactory for Arc<T>
where T: ValueParserFactory + Send + Sync + Clone, <T as ValueParserFactory>::Parser: TypedValueParser<Value = T>,

Source§

#### type Parser = MapValueParser<<T as ValueParserFactory>::Parser, fn(T) -> Arc<T>>

Source§

#### fn value_parser() -> <Arc<T> as ValueParserFactory>::Parser

Source§

### impl<T> ValueParserFactory for Box<T>
where T: ValueParserFactory + Send + Sync + Clone, <T as ValueParserFactory>::Parser: TypedValueParser<Value = T>,

Source§

#### type Parser = MapValueParser<<T as ValueParserFactory>::Parser, fn(T) -> Box<T>>

Source§

#### fn value_parser() -> <Box<T> as ValueParserFactory>::Parser

Source§

### impl<T> ValueParserFactory for Saturating<T>
where T: ValueParserFactory + Send + Sync + Clone, <T as ValueParserFactory>::Parser: TypedValueParser<Value = T>,

Source§

#### type Parser = MapValueParser<<T as ValueParserFactory>::Parser, fn(T) -> Saturating<T>>

Source§

#### fn value_parser() -> <Saturating<T> as ValueParserFactory>::Parser

Source§

### impl<T> ValueParserFactory for Wrapping<T>
where T: ValueParserFactory + Send + Sync + Clone, <T as ValueParserFactory>::Parser: TypedValueParser<Value = T>,

Source§

#### type Parser = MapValueParser<<T as ValueParserFactory>::Parser, fn(T) -> Wrapping<T>>

Source§

#### fn value_parser() -> <Wrapping<T> as ValueParserFactory>::Parser

## Implementors§