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>
impl<I: Iterator<Item = Result<char>>> Buffer<I>
sourcepub fn new(input: I, position: Position) -> Buffer<I>
pub fn new(input: I, position: Position) -> Buffer<I>
Create a new empty buffer starting at the given position.
sourcepub fn index_at(&self, pos: Position) -> Option<Result<usize>>
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.
sourcepub fn at(&self, pos: Position) -> Option<Result<char>>
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.
sourcepub fn iter(&self) -> Iter<'_, I> ⓘ
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.
sourcepub fn iter_from(&self, pos: Position) -> Iter<'_, I> ⓘ
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.