mipl 0.2.1

Minimal Imperative Parsing Library
Documentation
use super::*;
use std::collections::HashSet;

/// In the spirits of [ExactMatch], check if a predefined set
/// contains the next possible [Token::Str] string exactly.
pub struct OrExactMatch {
    matches: HashSet<String>
}
impl Peeker for OrExactMatch {
    type Item = String;

    fn peek_for_token(&self, parser: &mut Parser) -> Option<Token> {
        if let Token::Str(s) = parser.peek()? {
            if self.matches.contains(&s) {
                Some(Token::Str(s))
            } else {
                None
            }
        } else {
            None
        }
    }
}

impl IsContainerCpInput for Vec<String> {}
impl ContainedType for HashSet<String> {}

impl ContainerCp for OrExactMatch {
    type ContainedType = HashSet<String>;
    type Input = Vec<String>;

    fn new_contained(value: Self::Input) -> Self::ContainedType {
        HashSet::from_iter(value)
    }

    fn new(value: Self::Input) -> Self {
        OrExactMatch { matches: Self::new_contained(value) }
    }
}