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 str

The trailing part of the text that was not captured by any capture.

Note that no whitespace is trimmed.

Implementations

Returns Some(Match) if the capture with the name name has matched.

Returns Some(&str) if the name has matched and is a capture that matches at most once (no quantifier or the ? quantifier).

Returns Some(&Vec) if the name has matched and is a capture that can match multiple times (quantifiers * and +).

Takes the underlying HashMap from this match.

Returns true if name has any matches.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.