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>
impl<E, I: Iterator<Item = Result<char, E>>, M: Metrics> SourceBuffer<E, I, M>
Sourcepub fn new(input: I, position: Position, metrics: M) -> Self
pub fn new(input: I, position: Position, metrics: M) -> Self
Create a new empty buffer starting at the given position.
Sourcepub fn index_at(&self, pos: Position) -> Result<Option<usize>, E>
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.
Sourcepub fn at(&self, pos: Position) -> Result<Option<char>, E>
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.
Sourcepub fn get(&self, i: usize) -> Result<Option<char>, E>
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.
Sourcepub fn iter(&self) -> Iter<'_, E, I, M>
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.
Sourcepub fn iter_from(&self, pos: Position) -> Iter<'_, E, I, M>
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.
Sourcepub fn iter_span(&self, span: Span) -> Iter<'_, E, I, M>
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.