1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct State { index: usize, row: u64, col: u64, } unsafe impl Send for State {} unsafe impl Sync for State {} impl Default for State { #[inline(always)] fn default() -> Self { State { index: 0usize, row: 1u64, col: 1u64, } } } impl State { #[inline(always)] pub fn new() -> Self { Self::default() } #[inline(always)] pub fn index(&self) -> usize { self.index } #[inline(always)] pub fn row(&self) -> u64 { self.row } #[inline(always)] pub fn col(&self) -> u64 { self.col } #[inline] pub(crate) fn read(&mut self, is_newline: bool) { if is_newline { self.row += 1; self.col = 1; } else if self.index != 0 { self.col += 1; } self.index += 1; } }