pub trait ParseArg: Sized {
type Error: Display;
// Required methods
fn parse_arg(arg: &OsStr) -> Result<Self, Self::Error>;
fn describe_type<W: Write>(writer: W) -> Result;
// Provided method
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 important
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()
.)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl ParseArg for Box<str>
This implementation simply parses the “fat” owned type and converts it into the box.
impl ParseArg for Box<str>
This implementation simply parses the “fat” owned type and converts it into the box.
Source§impl ParseArg for Box<OsStr>
This implementation simply parses the “fat” owned type and converts it into the box.
impl ParseArg for Box<OsStr>
This implementation simply parses the “fat” owned type and converts it into the box.
Source§impl ParseArg for Box<Path>
This implementation simply parses the “fat” owned type and converts it into the box.
impl ParseArg for Box<Path>
This implementation simply parses the “fat” owned type and converts it into the box.
Source§impl ParseArg for AtomicIsize
impl ParseArg for AtomicIsize
Source§impl ParseArg for AtomicUsize
impl ParseArg for AtomicUsize
Source§impl ParseArg for OsString
This implementation is a no-op or clone, since OsString
is already OsString
.
impl ParseArg for OsString
This implementation is a no-op or clone, since OsString
is already OsString
.