Struct Arg

Source
pub struct Arg<'a> {
    pub name: &'a str,
    pub short: Option<&'a str>,
    pub long: Option<&'a str>,
    pub about: &'a str,
    pub num_values: NumValues,
    pub value_name: Option<&'a str>,
    pub default: Option<fn() -> Value>,
    pub required: bool,
    pub value_type: Type,
    pub validation: fn(&Value) -> Result<(), String>,
}
Expand description

Struct defining a single arg we can accept

Fields§

§name: &'a str

unique key (per Args) to identify this arg

§short: Option<&'a str>

short (single dash, e.g -v) alias to match this arg with @note: if multiple args have the same “short” or “long” name then we have a race condition. We do not check for this but which we use should be considered undefined behaviour

§long: Option<&'a str>

long (double dash, e.g –verbose) alias to match this arg with

§about: &'a str

info about this arg, used when printing –help

§num_values: NumValues

number of parameters this arg accepts. See NumValues for more details

§value_name: Option<&'a str>

name for the value of this arg in –help, used when printing –help

§default: Option<fn() -> Value>

default value for this arg if it is missing. By default no default is given

§required: bool

whether this arg is required

§value_type: Type

type for values, if given argparsing will fail if given the wrong type + Error::WrongValueType

§validation: fn(&Value) -> Result<(), String>

additional validation for this arg. By default is a noop If this returns Err(String) argparsing will fail with the given string + Error::InvalidValue

Trait Implementations§

Source§

impl<'a> Default for Arg<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Arg<'a>

§

impl<'a> RefUnwindSafe for Arg<'a>

§

impl<'a> Send for Arg<'a>

§

impl<'a> Sync for Arg<'a>

§

impl<'a> Unpin for Arg<'a>

§

impl<'a> UnwindSafe for Arg<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> Handler<'a, T> for T
where T: Default,

Source§

fn handler() -> fn(Results<'a>) -> T

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.