Skip to main content

LineBuffer

Struct LineBuffer 

Source
pub struct LineBuffer<'input> { /* private fields */ }
Expand description

A one-line-lookahead buffer over a &'input str.

Always holds the next line pre-parsed. Callers use Self::peek_next to inspect without consuming and Self::consume_next to advance.

Implementations§

Source§

impl<'input> LineBuffer<'input>

Source

pub fn new(input: &'input str) -> Self

Construct a new LineBuffer and prime the next-line slot.

Source

pub fn prepend_line(&mut self, line: Line<'input>)

Prepend a synthetic line that will be returned by the next call to Self::peek_next / Self::consume_next, ahead of any real lines.

Used to re-present inline content extracted from a sequence- or mapping-entry line as if it were a separate line. Multiple prepends are supported: each call pushes to the front of the queue, so the last prepended line is returned first (LIFO order). Callers that need FIFO order (key before value) should prepend value first, then key.

Source

pub fn peek_next(&self) -> Option<&Line<'input>>

Look at the next line without consuming it.

Returns the frontmost prepended synthetic line first (if any), then the normally buffered next line.

Source

pub fn is_next_synthetic(&self) -> bool

Returns true if the next line comes from the prepend queue (synthetic), rather than from the original input stream.

Source

pub fn peek_next_indent(&self) -> Option<usize>

Convenience: the indent of the next line, without consuming it.

Source

pub fn peek_second(&self) -> Option<Line<'input>>

Peek at the second upcoming line without consuming either.

Handles the prepend queue: the second line may come from the prepend queue or from the primed next slot or from remaining.

Source

pub fn consume_next(&mut self) -> Option<Line<'input>>

Advance: return the currently primed next line and prime the following one from the remaining input. Returns None when no lines remain.

Drains prepended synthetic lines (front-first) before the real buffer.

Source

pub fn at_eof(&self) -> bool

True when no more lines are available (buffer is empty, no prepend, and input is exhausted).

Source

pub fn peek_until_dedent(&mut self, base_indent: usize) -> &[Line<'input>]

Scan forward without consuming to collect all lines with indent > base_indent, stopping at the first line with indent <= base_indent. Blank lines (empty content) are transparent to the scan and are included in the result regardless of their indent.

Returns a slice of the buffered lookahead lines. Calling this method repeatedly (without consuming) returns the same slice.

Note: trailing blank lines in the returned slice are not part of the block scalar content — per YAML chomping rules, trailing blank lines are stripped, clipped, or kept based on the chomping indicator. The consumer (lexer, Task 8) is responsible for trimming them.

Auto Trait Implementations§

§

impl<'input> Freeze for LineBuffer<'input>

§

impl<'input> RefUnwindSafe for LineBuffer<'input>

§

impl<'input> Send for LineBuffer<'input>

§

impl<'input> Sync for LineBuffer<'input>

§

impl<'input> Unpin for LineBuffer<'input>

§

impl<'input> UnsafeUnpin for LineBuffer<'input>

§

impl<'input> UnwindSafe for LineBuffer<'input>

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.