pub struct ChunkCursor<'a> {
text: &'a str,
current_end: usize,
start_line_no: i64,
next_line_no: i64,
}Expand description
A forward cursor over the input that yields one chunk at a time.
Each chunk is a contiguous slice of the input spanning one or more physical
lines. Use peek_line to inspect the next line, merge to extend the
current chunk to include it, and next to finish the chunk and obtain a
cursor for what follows. See the module docs for the overall model.
The cursor is move-only on purpose: next consumes it by value, so a
finished chunk cannot be accidentally reused or finished twice.
Fields§
§text: &'a strThe original input, starting at the first byte of the current chunk.
current_end: usizeNumber of bytes of text merged into the current chunk so far. The
chunk is &text[..current_end]; this always sits on a line boundary.
start_line_no: i641-based line number of the chunk’s first physical line.
next_line_no: i64Line number that the next peek_line will return.
Equivalently, start_line_no + (lines merged so far).
Implementations§
Source§impl<'a> ChunkCursor<'a>
impl<'a> ChunkCursor<'a>
Sourcepub fn new(text: &'a str, start_line_no: i64) -> Option<Self>
pub fn new(text: &'a str, start_line_no: i64) -> Option<Self>
Create a cursor over text, whose first physical line is numbered
start_line_no. Returns None if text is empty (no chunk to build).
Sourcepub fn start_line_no(&self) -> i64
pub fn start_line_no(&self) -> i64
1-based line number of the chunk’s first physical line.
Sourcepub fn peek_line(&self) -> Option<Line<'a>>
pub fn peek_line(&self) -> Option<Line<'a>>
The next physical line after the current chunk, without consuming it.
Returns None once the whole input has been consumed.
Sourcepub fn merge(&mut self, line: Line<'a>)
pub fn merge(&mut self, line: Line<'a>)
Extend the current chunk to include line.
line must be the value most recently returned by peek_line on this
same cursor; passing anything else is a programming error.
Sourcepub fn next(self) -> (&'a str, Option<ChunkCursor<'a>>)
pub fn next(self) -> (&'a str, Option<ChunkCursor<'a>>)
Finish the current chunk: return its text together with a cursor for the
next chunk, or None if the input is exhausted.