Trait CommandLineArgument

Source
pub trait CommandLineArgument {
    // Required methods
    fn parse_value(&mut self, arg: &str) -> Result<(), ArgError>;
    fn write_name(&self, name: Option<&str>) -> Option<String>;

    // Provided methods
    fn set_default(&mut self) -> Result<(), ArgError> { ... }
    fn set_unseen(&mut self) { ... }
    fn is_multi(&self) -> bool { ... }
    fn default_value(&self) -> Option<String> { ... }
}
Expand description

Trait for variables that can be used as option arguments.

Required Methods§

Source

fn parse_value(&mut self, arg: &str) -> Result<(), ArgError>

Add the value from the command line string.

Source

fn write_name(&self, name: Option<&str>) -> Option<String>

Return a description of a argument of this type.

name is a use-defined description (if any) of the underlying type. The function may add additional formatting.

Provided Methods§

Source

fn set_default(&mut self) -> Result<(), ArgError>

Called if the option has been specified without argument.

The method should return the error ArgError::MissingArgument if the argument is required.

Source

fn set_unseen(&mut self)

Called if the argument has never been seen.

This method can be used to store a specific “never seen” value in the variable.

Source

fn is_multi(&self) -> bool

Return true if the argument can parsed multiple times.

Source

fn default_value(&self) -> Option<String>

Return the initial value as a string.

Implementations on Foreign Types§

Source§

impl<'a> CommandLineArgument for &'a mut bool

A flag.

A flag must not take an argument but always uses its default value.

Source§

fn parse_value(&mut self, arg: &str) -> Result<(), ArgError>

Source§

fn set_default(&mut self) -> Result<(), ArgError>

Source§

fn write_name(&self, _name: Option<&str>) -> Option<String>

Source§

impl<'a, T> CommandLineArgument for &'a mut Option<T>
where T: FromStr + DefaultName + Display, <T as FromStr>::Err: StdError + 'static,

An optional argument option.

Source§

fn parse_value(&mut self, arg: &str) -> Result<(), ArgError>

Source§

fn set_default(&mut self) -> Result<(), ArgError>

Source§

fn set_unseen(&mut self)

Source§

fn default_value(&self) -> Option<String>

Source§

fn write_name(&self, name: Option<&str>) -> Option<String>

Implementors§

Source§

impl<'a, T> CommandLineArgument for Multi<&'a mut Vec<T>>
where T: FromStr + DefaultName + Debug, <T as FromStr>::Err: StdError + 'static,

Source§

impl<'a, T> CommandLineArgument for Single<&'a mut T>
where T: FromStr + DefaultName + Display, <T as FromStr>::Err: StdError + 'static,