1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pub(crate) struct ParserState {
    pub(crate) offset: usize,
}

pub(crate) fn read<'a>(input: &'a [u8], state: &mut ParserState, n: usize) -> Option<&'a [u8]> {
    if state.offset + n <= input.len() {
        let slice = &input[state.offset..state.offset + n];
        state.offset += n;
        Some(slice)
    } else {
        None
    }
}

#[inline]
pub(crate) fn is_empty(input: &[u8], state: &ParserState) -> bool {
    state.offset == input.len()
}

#[derive(Debug)]
pub enum Either<A, B> {
    A(A),
    B(B),
}