pub struct ArgInfo<'a> {
pub name: Cow<'a, str>,
pub value: Option<Cow<'a, OsStr>>,
}Fields§
§name: Cow<'a, str>§value: Option<Cow<'a, OsStr>>Implementations§
Source§impl<'a> ArgInfo<'a>
impl<'a> ArgInfo<'a>
Sourcepub fn parse(val: &'a OsStr) -> Result<Self, Error>
pub fn parse(val: &'a OsStr) -> Result<Self, Error>
Parse the input command line item with given regexs, return an ArgInfo.
The struct of the input option string are:
[--/option][=][value]
| | |
| | |
| | The value part, it is optional.
| |
| The delimiter of option name and value.
|
The option name part, it must be provide by user.§Example
{// parse option with value
let output = ArgInfo::parse(OsStr::new("--foo=32"))?;
assert_eq!(output.name, "--foo");
assert_eq!(output.value.as_deref(), Some(OsStr::new("32")));
}
{// parse boolean option
let output = ArgInfo::parse(OsStr::new("--/bar"))?;
assert_eq!(output.name, "--/bar");
assert_eq!(output.value, None);
}
{// parse other string
let output = ArgInfo::parse(OsStr::new("-=bar"))?;
assert_eq!(output.name, "-");
assert_eq!(output.value.as_deref(), Some(OsStr::new("bar")));
}Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ArgInfo<'a>
impl<'a> RefUnwindSafe for ArgInfo<'a>
impl<'a> Send for ArgInfo<'a>
impl<'a> Sync for ArgInfo<'a>
impl<'a> Unpin for ArgInfo<'a>
impl<'a> UnwindSafe for ArgInfo<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more