Skip to main content

ParseArg

Trait ParseArg 

Source
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§

Source

type Error: Display

Type returned in the Err variant of Result when parsing fails.

Required Methods§

Source

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

Parses the argument.

Source

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§

Source

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".

Implementations on Foreign Types§

Source§

impl ParseArg for Arc<OsStr>

Available on target_has_atomic=ptr only.
Source§

type Error = Infallible

Source§

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

Source§

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

Source§

impl ParseArg for Arc<Path>

Available on target_has_atomic=ptr only.
Source§

type Error = Infallible

Source§

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

Source§

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

Source§

impl ParseArg for Arc<str>

Available on target_has_atomic=ptr only.
Source§

impl ParseArg for AtomicI8

Available on target_has_atomic=8 only.
Source§

impl ParseArg for AtomicI16

Available on target_has_atomic=16 only.
Source§

impl ParseArg for AtomicI32

Available on target_has_atomic=32 only.
Source§

impl ParseArg for AtomicI64

Available on target_has_atomic=64 only.
Source§

impl ParseArg for AtomicIsize

Available on target_has_atomic=ptr only.
Source§

impl ParseArg for AtomicU8

Available on target_has_atomic=8 only.
Source§

impl ParseArg for AtomicU16

Available on target_has_atomic=16 only.
Source§

impl ParseArg for AtomicU32

Available on target_has_atomic=32 only.
Source§

impl ParseArg for AtomicU64

Available on target_has_atomic=64 only.
Source§

impl ParseArg for AtomicUsize

Available on target_has_atomic=ptr only.
Source§

impl ParseArg for Box<OsStr>

This implementation simply parses the “fat” owned type and converts it into the box.

Source§

type Error = <<OsStr as ToOwned>::Owned as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl ParseArg for Box<Path>

This implementation simply parses the “fat” owned type and converts it into the box.

Source§

type Error = <<Path as ToOwned>::Owned as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl ParseArg for Box<str>

This implementation simply parses the “fat” owned type and converts it into the box.

Source§

type Error = <<str as ToOwned>::Owned as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl ParseArg for Cow<'static, OsStr>

Source§

type Error = <<OsStr as ToOwned>::Owned as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl ParseArg for Cow<'static, Path>

Source§

type Error = <<Path as ToOwned>::Owned as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl ParseArg for Cow<'static, str>

Source§

type Error = <<str as ToOwned>::Owned as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl ParseArg for OsString

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

Source§

type Error = Infallible

Source§

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

Source§

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

Source§

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

Source§

impl ParseArg for PathBuf

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

Source§

type Error = Infallible

Source§

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

Source§

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

Source§

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

Source§

impl ParseArg for Rc<OsStr>

Source§

type Error = Infallible

Source§

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

Source§

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

Source§

impl ParseArg for Rc<Path>

Source§

type Error = Infallible

Source§

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

Source§

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

Source§

impl ParseArg for Rc<str>

Source§

impl ParseArg for String

Optimized implementation - doesn’t allocate in parse_owned_arg.

Source§

impl<T: ParseArg> ParseArg for Arc<T>

Available on target_has_atomic=ptr only.
Source§

type Error = <T as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl<T: ParseArg> ParseArg for Cell<T>

Source§

type Error = <T as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl<T: ParseArg> ParseArg for ManuallyDrop<T>

Source§

type Error = <T as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl<T: ParseArg> ParseArg for Mutex<T>

Source§

type Error = <T as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl<T: ParseArg> ParseArg for Rc<T>

Source§

type Error = <T as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl<T: ParseArg> ParseArg for RefCell<T>

Source§

type Error = <T as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl<T: ParseArg> ParseArg for RwLock<T>

Source§

type Error = <T as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Source§

impl<T: ParseArg> ParseArg for UnsafeCell<T>

Source§

type Error = <T as ParseArg>::Error

Source§

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

Source§

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

Source§

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

Implementors§

Source§

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