use crate::{PResult, Parser, ParserInput};
#[derive(Clone, Copy)]
pub struct Just {
str: &'static str,
}
impl Just {
pub fn new(str: &'static str) -> Self {
Self { str }
}
}
impl Parser<&'static str> for Just {
fn parse_inner(&self, input: &mut ParserInput) -> PResult<&'static str> {
let start = input.at();
let eaten = input
.try_eat(self.str.len())
.ok_or_else(|| start.expected_str(self.str, 0))?;
if eaten.data == self.str {
Ok(eaten.replace(self.str))
} else {
Err(start.expected_str(self.str, eaten.at.len))
}
}
}