Function or

Source
pub fn or<V>(tokens: V) -> Token
where V: IntoIterator<Item = Token>,
Expand description

Matches exactly one of a set of possible tokens. The matched token will be included in the result.

ยงExamples

use initiative_core::command::prelude::*;

let token = or([keyword("badger"), any_word()]);

assert_eq!(
    vec![
        // "badger" matches a provided keyword,
        FuzzyMatch::Overflow(
            TokenMatch::new(&token, TokenMatch::from(&keyword("badger"))),
            " badger".into(),
        ),

        // but it satisfies the wildcard any_word() case as well.
        // It only ever matches a single token, so the second "badger" in the input is
        // never consumed.
        FuzzyMatch::Overflow(
            TokenMatch::new(&token, TokenMatch::new(&any_word(), "badger")),
            " badger".into(),
        ),
    ],
    token
        .match_input("badger badger", &app_meta)
        .collect::<Vec<_>>()
        .await,
);