Skip to main content

ChunkCursor

Struct ChunkCursor 

Source
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 str

The original input, starting at the first byte of the current chunk.

§current_end: usize

Number 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: i64

1-based line number of the chunk’s first physical line.

§next_line_no: i64

Line number that the next peek_line will return. Equivalently, start_line_no + (lines merged so far).

Implementations§

Source§

impl<'a> ChunkCursor<'a>

Source

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).

Source

pub fn start_line_no(&self) -> i64

1-based line number of the chunk’s first physical line.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a> Debug for ChunkCursor<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ChunkCursor<'a>

§

impl<'a> RefUnwindSafe for ChunkCursor<'a>

§

impl<'a> Send for ChunkCursor<'a>

§

impl<'a> Sync for ChunkCursor<'a>

§

impl<'a> Unpin for ChunkCursor<'a>

§

impl<'a> UnsafeUnpin for ChunkCursor<'a>

§

impl<'a> UnwindSafe for ChunkCursor<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.