Struct SourceBuffer

Source
pub struct SourceBuffer<E, I: Iterator<Item = Result<char, E>>, M: Metrics> { /* private fields */ }
Expand description

Lazy string buffer that fills up on demand, can be iterated and indexed by character position.

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

Implementations§

Source§

impl<E, I: Iterator<Item = Result<char, E>>, M: Metrics> SourceBuffer<E, I, M>

Source

pub fn new(input: I, position: Position, metrics: M) -> Self

Create a new empty buffer starting at the given position.

Source

pub fn metrics(&self) -> &M

Get the metrics used by the source buffer to map every character.

Source

pub fn span(&self) -> Span

Get the span of the entire buffered data.

Source

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

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) -> Result<Option<char>, E>

Get the char at the given position if it is in the buffer. If it is not in the buffer yet, the input stream will be pulled until the buffer span includes the given position.

Returns None if the given position is out of range, 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 get(&self, i: usize) -> Result<Option<char>, E>

Get the character at the given index.

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 source stream ends before the given position.

Source

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

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<'_, E, I, M>

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

If the input position precedes the buffer start position, then 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.

Source

pub fn iter_span(&self, span: Span) -> Iter<'_, E, I, M>

Returns an iterator through the characters of the buffer in the given span.

If the input start position precedes the buffer start position, then 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<E, I, M> !Freeze for SourceBuffer<E, I, M>

§

impl<E, I, M> !RefUnwindSafe for SourceBuffer<E, I, M>

§

impl<E, I, M> Send for SourceBuffer<E, I, M>
where M: Send, I: Send, E: Send,

§

impl<E, I, M> !Sync for SourceBuffer<E, I, M>

§

impl<E, I, M> Unpin for SourceBuffer<E, I, M>
where M: Unpin, I: Unpin, E: Unpin,

§

impl<E, I, M> UnwindSafe for SourceBuffer<E, I, M>
where M: UnwindSafe, I: UnwindSafe, E: UnwindSafe,

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.