[][src]Trait parse_arg::ParseArg

pub trait ParseArg: Sized {
    type Error: Display;
    fn parse_arg(arg: &OsStr) -> Result<Self, Self::Error>;
fn describe_type<W: Write>(writer: W) -> Result; fn parse_owned_arg(arg: OsString) -> Result<Self, Self::Error> { ... } }

Defines an interface for types that can be created by parsing command-line argument.

This trait is similar to FromStr. See the crate documentation for list of importatn differences.

Associated Types

type Error: Display

Type returned in Err variant of Result when parsing fails.

Loading content...

Required methods

fn parse_arg(arg: &OsStr) -> Result<Self, Self::Error>

Parses the argument.

fn describe_type<W: Write>(writer: W) -> Result

Writes human-readable description of the type to the writer.

The description should be in English composed in such way that appending it to string "The input must be " sounds natural. E.g. if the description is "a number", the resulting phrase will be "The input must be a number".

This way, it can be used as a documentation/hint for the user.

Loading content...

Provided methods

fn parse_owned_arg(arg: OsString) -> Result<Self, Self::Error>

Parses the argument consuming it.

Implementors are encouraged to specialize this method if the resulting implementation is more performant - e.g. if it avoids allocation.

The users are encouraged to use this method instead of parse_arg if they own the string and will not need it after call to this function. (Typical when working with std::env::args_os().)

Loading content...

Implementations on Foreign Types

impl ParseArg for String[src]

Optimized implementation - doesn't allocate in parse_owned_arg.

type Error = ParseArgError<ParseError>

impl ParseArg for OsString[src]

This implementation is a no-op or clone, since OsString is already OsString.

type Error = ParseError

impl ParseArg for PathBuf[src]

To my knowledge this is a no-op or clone.

type Error = ParseError

Loading content...

Implementors

impl<T> ParseArg for T where
    T: ParseArgFromStr,
    <T as FromStr>::Err: Display
[src]

type Error = ParseArgError<<T as FromStr>::Err>

Loading content...