Struct source_span::lazy::Buffer

source ·
pub struct Buffer<I: Iterator<Item = Result<char>>> { /* private fields */ }
Expand description

Lazy string buffer that fills up on demand.

The lazy::Buffer wraps aroung a char iterator. It can be itself used as a char iterator, or as a Buffer to access an arbitrary fragment of the input source stream.

Implementations§

source§

impl<I: Iterator<Item = Result<char>>> Buffer<I>

source

pub fn new(input: I, position: Position) -> Buffer<I>

Create a new empty buffer starting at the given position.

source

pub fn span(&self) -> Span

Get the span of the entire buffered data.

source

pub fn index_at(&self, pos: Position) -> Option<Result<usize>>

Get the index of the char at the given cursor position if it is in the buffer. If it is not in the buffer but after the buffered content, the input stream will be read until the buffer span includes the given position.

Returns None if the given position if previous to the buffer start positions, if the source stream ends before the given position, or if the line at the given position is shorter than the given position column.

source

pub fn at(&self, pos: Position) -> Option<Result<char>>

Get the char at the given position if it is in the buffer. If it is not in the buffer but after the buffered content, the input stream will be read until the buffer span includes the given position.

Returns None if the given position if previous to the buffer start positions, if the source stream ends before the given position, or if the line at the given position is shorter than the given position column.

source

pub fn iter(&self) -> Iter<'_, I>

Returns an iterator through the characters of the buffer from the begining of it.

When it reaches the end of the buffer, the buffer will start reading from the source stream.

source

pub fn iter_from(&self, pos: Position) -> Iter<'_, I>

Returns an iterator through the characters of the buffer from the given position.

If the input position precedes the buffer start position, that it will start from the buffer start position. When it reaches the end of the buffer, the buffer will start reading from the source stream.

Auto Trait Implementations§

§

impl<I> !Freeze for Buffer<I>

§

impl<I> !RefUnwindSafe for Buffer<I>

§

impl<I> Send for Buffer<I>
where I: Send,

§

impl<I> !Sync for Buffer<I>

§

impl<I> Unpin for Buffer<I>
where I: Unpin,

§

impl<I> !UnwindSafe for Buffer<I>

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>,

§

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>,

§

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.