use crate::iterator::PosCounter; use source_stream_0::Pos; pub struct PosLineCol { pub row: usize, pub col: usize, } impl Pos<'static> for PosLineCol {} pub struct NewLinePosCounter { row: usize, col: usize, } impl NewLinePosCounter { pub fn _update(&mut self, actual: C, expected: C) { if actual == expected { self.row += 1; self.col = 0; } else { self.col += 1; } } pub fn _export(&self) -> PosLineCol { return PosLineCol { row: self.row, col: self.col, }; } pub fn _init() -> Self { return NewLinePosCounter { row: 0, col: 0 }; } } impl PosCounter<'static, char, PosLineCol> for NewLinePosCounter { fn update(&mut self, c: char) { self._update(c, '\n') } fn export(&self) -> PosLineCol { self._export() } fn init() -> Self { return NewLinePosCounter::_init(); } } impl PosCounter<'static, u8, PosLineCol> for NewLinePosCounter { fn update(&mut self, c: u8) { self._update(c, b'\n') } fn export(&self) -> PosLineCol { self._export() } fn init() -> Self { return NewLinePosCounter::_init(); } }