Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/serde_json/src/iter.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / serde_json / src / iter.rs` 70 lines ยท 1848 bytes Raw Blame History 1 use crate::io; 2 3 pub struct LineColIterator { 4 iter: I, 5 6 /// Index of the current line. Characters in the first line of the input 7 /// (before the first newline character) are in line 1. 8 line: usize, 9 10 /// Index of the current column. The first character in the input and any 11 /// characters immediately following a newline character are in column 1. 12 /// The column is 0 immediately after a newline character has been read. 13 col: usize, 14 15 /// Byte offset of the start of the current line. This is the sum of lengths 16 /// of all previous lines. Keeping track of things this way allows efficient 17 /// computation of the current line, column, and byte offset while only 18 /// updating one of the counters in `next()` in the common case. 19 start_of_line: usize, 20 } 21 22 impl LineColIterator 23 where 24 I: Iterator>, 25 { 26 pub fn new(iter: I) -> LineColIterator { 27 LineColIterator { 28 iter, 29 line: 1, 30 col: 0, 31 start_of_line: 0, 32 } 33 } 34 35 pub fn line(&self) -> usize { 36 self.line 37 } 38 39 pub fn col(&self) -> usize { 40 self.col 41 } 42 43 pub fn byte_offset(&self) -> usize { 44 self.start_of_line + self.col 45 } 46 } 47 48 impl Iterator for LineColIterator 49 where 50 I: Iterator>, 51 { 52 type Item = io::Result; 53 54 fn next(&mut self) -> Option> { 55 match self.iter.next() { 56 None => None, 57 Some(Ok(b'\n')) => { 58 self.start_of_line += self.col + 1; 59 self.line += 1; 60 self.col = 0; 61 Some(Ok(b'\n')) 62 } 63 Some(Ok(c)) => { 64 self.col += 1; 65 Some(Ok(c)) 66 } 67 Some(Err(e)) => Some(Err(e)), 68 } 69 } 70 }