sac13 0.1.1

The reference implementation for the SAC13 calendar system.
Documentation
pub struct ByteSliceIter<'a> {
    pub position: usize,
    pub slice: &'a [u8],
}

impl<'a> ByteSliceIter<'a> {
    pub fn skip_bytes(&mut self, value: u8) {
        while let Some(v) = self.peek()
            && v == value
        {
            self.next();
        }
    }

    pub fn peek(&self) -> Option<u8> {
        self.slice.get(self.position).copied()
    }

    /// peek_n(-1) reports the value that was reported by the last next() call
    /// peek_n(0)  reports the value that will be returned by the next next() call
    pub fn peek_n(&self, relative: isize) -> Option<u8> {
        let target_pos = self.position as isize + relative;

        if target_pos < 0 {
            return None;
        }

        let target_pos = target_pos as usize;

        self.slice.get(target_pos).copied()
    }
}

impl<'a> Iterator for ByteSliceIter<'a> {
    type Item = u8;

    fn next(&mut self) -> Option<Self::Item> {
        if self.position >= self.slice.len() {
            return None;
        }

        let item = self.slice[self.position];
        self.position += 1;

        Some(item)
    }
}