oni_comb_parser/text/
char.rs1use crate::error::ParseError;
2use crate::fail::{Fail, PResult};
3use crate::input::Input;
4use crate::parser::Parser;
5use crate::str_input::StrInput;
6
7pub struct Char(char);
8
9pub fn char(c: char) -> Char {
10 Char(c)
11}
12
13impl Parser<StrInput<'_>> for Char {
14 type Error = ParseError;
15 type Output = char;
16
17 #[inline]
18 fn parse_next(&mut self, input: &mut StrInput<'_>) -> PResult<Self::Output, Self::Error> {
19 let pos = input.offset();
20 let remaining = input.remaining();
21 match remaining.chars().next() {
22 Some(c) if c == self.0 => {
23 input.advance(c.len_utf8());
24 Ok(c)
25 }
26 _ => Err(Fail::Backtrack(ParseError::expected_char(pos, self.0))),
27 }
28 }
29}