# Trait clap::builder::ValueParserFactory

source · [−]

    pub trait ValueParserFactory {
        type Parser;

        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`

## Implementations on Foreign Types

source

### impl ValueParserFactory for String

#### type Parser = ValueParser

source

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

source

### impl ValueParserFactory for OsString

#### type Parser = ValueParser

source

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

source

### impl ValueParserFactory for PathBuf

#### type Parser = ValueParser

source

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

source

### impl ValueParserFactory for bool

#### type Parser = ValueParser

source

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

source

### impl ValueParserFactory for u8

#### type Parser = RangedI64ValueParser<u8>

source

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

source

### impl ValueParserFactory for i8

#### type Parser = RangedI64ValueParser<i8>

source

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

source

### impl ValueParserFactory for u16

#### type Parser = RangedI64ValueParser<u16>

source

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

source

### impl ValueParserFactory for i16

#### type Parser = RangedI64ValueParser<i16>

source

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

source

### impl ValueParserFactory for u32

#### type Parser = RangedI64ValueParser<u32>

source

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

source

### impl ValueParserFactory for i32

#### type Parser = RangedI64ValueParser<i32>

source

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

source

### impl ValueParserFactory for i64

#### type Parser = RangedI64ValueParser<i64>

source

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

source

### impl ValueParserFactory for u64

#### type Parser = RangedU64ValueParser<u64>

source

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

## Implementors