[−][src]Trait ctflag::FromArg
Any type declared in a struct that derives ctflag::Flags
must implement
this trait. A blanket implementation exists for types implementing FromStr
.
Custom types can implement this trait directly.
enum Fruit { Apple, Orange, } impl FromArg for Fruit { fn from_arg(s: &str) -> FromArgResult<Self> { match s { "apple" => Ok(Fruit::Apple), "orange" => Ok(Fruit::Orange), _ => Err(FromArgError::with_message("bad fruit")), } } }
Required methods
fn from_arg(value: &str) -> FromArgResult<Self>
Parses a string s
to return the value of this type.
If parsing succeeds, return the value inside an Ok
, otherwise
return an error using [ctflag::FromArgError::with_message
] inside
an Err
.
[ctflag::FromArgError::with_message
]: struct.FromArgError.html#method.with_message