pub struct Args<'c, 't> {
pub rest: &'t str,
/* private fields */
}Expand description
Contains matches from a text matched by a Command.
Lifetime 'c refers to the command and 't refers to the text that was
matched.
Examples
use malachi::{
Command,
Match,
};
// Our command will create a note with a title
// and optionally some tags.
// Tags must start with `-`.
let cmd = Command::new(
"?note [
<tags*: starts('-')>
<title>
]",
)?;
// An example invocation.
let msg = "?note example This is an example note.";
let args = cmd
.get_matches(msg)
.ok_or("Command didn't match the message!")?;
// We get capture matches by their name.
assert_eq!(Some(&Match::Once("example")), args.get("title"),);
// We can use `get_once` to simplify it:
assert_eq!(Some("example"), args.get_once("title"),);
assert_eq!(None, args.get("tags"),);
// We can access the note body with args.rest:
assert_eq!(
// Notice the leading space, they are kept.
" This is an example note.",
args.rest,
);
// This time, lets supply some tags too.
let msg = "?note take2 -example -foo Another note!";
let args = cmd
.get_matches(msg)
.ok_or("Command didn't match the message!")?;
assert_eq!(Some("take2"), args.get_once("title"),);
assert_eq!(Some(&vec!["example", "foo"]), args.get_many("tags"),);
assert_eq!(" Another note!", args.rest,);
Fields
rest: &'t strThe trailing part of the text that was not captured by any capture.
Note that no whitespace is trimmed.
Implementations
sourceimpl<'c, 't, 'z: 'c + 't> Args<'c, 't>
impl<'c, 't, 'z: 'c + 't> Args<'c, 't>
sourcepub fn get(&'z self, name: &str) -> Option<&'z Match<'t>>
pub fn get(&'z self, name: &str) -> Option<&'z Match<'t>>
Returns Some(Match) if the capture with the name name has matched.
sourcepub fn get_once(&'z self, key: &str) -> Option<&'z str>
pub fn get_once(&'z self, key: &str) -> Option<&'z str>
Returns Some(&str) if the name has matched and is a capture that
matches at most once (no quantifier or the ? quantifier).
sourcepub fn get_many(&'z self, key: &str) -> Option<&'z Vec<&'z str>>
pub fn get_many(&'z self, key: &str) -> Option<&'z Vec<&'z str>>
Returns Some(&Vec) if the name has matched and is a capture that can
match multiple times (quantifiers * and +).
sourcepub fn into_matches(self) -> HashMap<&'c str, Match<'t>>
pub fn into_matches(self) -> HashMap<&'c str, Match<'t>>
Takes the underlying HashMap from this match.
sourcepub fn is_present(&self, name: &str) -> bool
pub fn is_present(&self, name: &str) -> bool
Returns true if name has any matches.
pub fn take(&mut self, name: &str) -> Option<Match<'t>>
pub fn take_many(&mut self, name: &str) -> Option<Vec<&'t str>>
Trait Implementations
impl<'c, 't> Eq for Args<'c, 't>
impl<'c, 't> StructuralEq for Args<'c, 't>
impl<'c, 't> StructuralPartialEq for Args<'c, 't>
Auto Trait Implementations
impl<'c, 't> RefUnwindSafe for Args<'c, 't>
impl<'c, 't> Send for Args<'c, 't>
impl<'c, 't> Sync for Args<'c, 't>
impl<'c, 't> Unpin for Args<'c, 't>
impl<'c, 't> UnwindSafe for Args<'c, 't>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more