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§
Required Methods§
sourcefn describe_type<W: Write>(writer: W) -> Result
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.
Provided Methods§
sourcefn parse_owned_arg(arg: OsString) -> Result<Self, Self::Error>
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().)
Implementations on Foreign Types§
source§impl ParseArg for OsString
impl ParseArg for OsString
This implementation is a no-op or clone, since OsString is already OsString.