use detached_str::StrSlice;
use crate::{Input, ParseInfallible};
pub(crate) struct While<T>(pub T);
impl<F: Fn(char) -> bool> ParseInfallible for While<F> {
type Output = StrSlice;
fn parse_infallible(&self, input: &mut Input) -> Self::Output {
let mut input = input.start();
loop {
match input.peek_char() {
Some(c) if self.0(c) => {
input.bump(c.len_utf8() as usize);
}
_ => break,
};
}
input.apply()
}
}
impl ParseInfallible for While<char> {
type Output = StrSlice;
fn parse_infallible(&self, input: &mut Input) -> Self::Output {
let mut input = input.start();
loop {
match input.peek_char() {
Some(c) if c == self.0 => {
input.bump(c.len_utf8() as usize);
}
_ => break,
};
}
input.apply()
}
}