Trait app::OptValueParse [] [src]

pub trait OptValueParse<'app>: Debug {
    fn into_opt_value(self) -> OptValue<'app>;
    fn is_bool(&self) -> bool;
    fn parse(&mut self, opt_name: String, msg: &str) -> Result<(), String>;
    fn check(&self, opt_name: &str) -> Result<(), String>;
}

You can use custom OptValue by impl it

Explain

  • into_opt_value(self) convert it(&mut T) to OptValue.

  • is_bool(&self) like --help/-h,they not have value follows it.

    so you should return false except value's type is &mut bool(it already defined).

  • parse(&mut self, opt_name: String, msg: &str) maintains the value, and return message by Result<(),String>.

    opt_name is current Opt's name, msg is &str need to pasre.

  • check(&self, opt_name: &str) check value and return message by Result<(),String>.

Suggestion

  • T is suitable for options with default values.

    You can initialize it using the default value.

  • Option<T> is suitable for necessary options.

    app will check them, is value.is_none(), app will exit(1) after print error and help message.

  • Vec<T> is suitable a grout of comma-separated values of the same type.

    app will check them, is value.is_empty(), app will exit(1) after print error and help message.

    You can initialize it using the default value.

"80" -> vec[80]
",80," -> vec[80]
",80,," -> vec[80]
"8080,8000,80," -> Vec[8080,8000,80]

Required Methods

Implementors