Skip to main content

FromArg

Trait FromArg 

Source
pub trait FromArg: Sized {
    // Required method
    fn from_arg(raw: &str) -> Result<Self, String>;

    // Provided method
    fn type_name() -> &'static str { ... }
}
Expand description

Convert a raw command-line argument string into a typed value.

A blanket implementation covers every T: FromStr with a Display error, so any type that already implements FromStr works automatically. Implement this trait directly only for types that cannot use FromStr (for example, to support a custom syntax).

Required Methods§

Source

fn from_arg(raw: &str) -> Result<Self, String>

Provided Methods§

Source

fn type_name() -> &'static str

Human-readable name of the expected type, used in error messages.

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.

Implementors§

Source§

impl<T> FromArg for T
where T: FromStr, T::Err: Display,