Function keyword_m

Source
pub fn keyword_m<M>(marker: M, keyword: &'static str) -> Token
where M: Hash,
Expand description

A variant of keyword with a marker assigned, making it easy to jump directly to the matched result within the token tree.

ยงExamples

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

#[derive(Hash)]
enum Marker {
    Keyword,
}

let token = sequence([
    optional(keyword_m(Marker::Keyword, "badger")),
    keyword("mushroom"),
]);

// We can easily distinguish between the case when the keyword was matched
let query = "badger mushroom";
let token_match = token.match_input_exact(query, &app_meta).next().await.unwrap();
assert!(token_match.contains_marker(Marker::Keyword));

// and when it wasn't.
let query = "mushroom";
let token_match = token.match_input_exact(query, &app_meta).next().await.unwrap();
assert!(!token_match.contains_marker(Marker::Keyword));