Trait parse_arg::ParseArg

source ·
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> { ... }
}
Expand description

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.

Required Associated Types§

Type returned in Err variant of Result when parsing fails.

Required Methods§

Parses the argument.

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.

Provided Methods§

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().)

Implementations on Foreign Types§

Optimized implementation - doesn’t allocate in parse_owned_arg.

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

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

Implementors§