]>
git.proxmox.com Git - cargo.git/blob - vendor/serde_json/src/iter.rs
3 pub struct LineColIterator
<I
> {
6 /// Index of the current line. Characters in the first line of the input
7 /// (before the first newline character) are in line 1.
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.
15 /// Byte offset of the start of the current line. This is the sum of lenghts
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.
22 impl<I
> LineColIterator
<I
>
24 I
: Iterator
<Item
= io
::Result
<u8>>,
26 pub fn new(iter
: I
) -> LineColIterator
<I
> {
35 pub fn line(&self) -> usize {
39 pub fn col(&self) -> usize {
43 pub fn byte_offset(&self) -> usize {
44 self.start_of_line
+ self.col
48 impl<I
> Iterator
for LineColIterator
<I
>
50 I
: Iterator
<Item
= io
::Result
<u8>>,
52 type Item
= io
::Result
<u8>;
54 fn next(&mut self) -> Option
<io
::Result
<u8>> {
55 match self.iter
.next() {
58 self.start_of_line
+= self.col
+ 1;
67 Some(Err(e
)) => Some(Err(e
)),