Struct source_span::SourceBuffer [−][src]
pub struct SourceBuffer<E, I: Iterator<Item = Result<char, E>>, M: Metrics> { /* fields omitted */ }
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
impl<E, I: Iterator<Item = Result<char, E>>, M: Metrics> SourceBuffer<E, I, M>
[src]
impl<E, I: Iterator<Item = Result<char, E>>, M: Metrics> SourceBuffer<E, I, M>
[src]pub fn new(input: I, position: Position, metrics: M) -> Self
[src]
Create a new empty buffer starting at the given position.
pub fn metrics(&self) -> &M
[src]
Get the metrics used by the source buffer to map every character.
pub fn span(&self) -> Span
[src]
Get the span of the entire buffered data.
pub fn index_at(&self, pos: Position) -> Result<Option<usize>, E>
[src]
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.
pub fn at(&self, pos: Position) -> Result<Option<char>, E>
[src]
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.
pub fn get(&self, i: usize) -> Result<Option<char>, E>
[src]
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.
pub fn iter(&self) -> Iter<'_, E, I, M>
[src]
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.
pub fn iter_from(&self, pos: Position) -> Iter<'_, E, I, M>
[src]
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.
pub fn iter_span(&self, span: Span) -> Iter<'_, E, I, M>
[src]
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> !RefUnwindSafe 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
E: Send,
I: Send,
M: Send,
impl<E, I, M> Send for SourceBuffer<E, I, M> where
E: Send,
I: Send,
M: Send,
impl<E, I, M> !Sync for SourceBuffer<E, I, M>
impl<E, I, M> !Sync for SourceBuffer<E, I, M>
impl<E, I, M> Unpin for SourceBuffer<E, I, M> where
E: Unpin,
I: Unpin,
M: Unpin,
impl<E, I, M> Unpin for SourceBuffer<E, I, M> where
E: Unpin,
I: Unpin,
M: Unpin,
impl<E, I, M> UnwindSafe for SourceBuffer<E, I, M> where
E: UnwindSafe,
I: UnwindSafe,
M: UnwindSafe,
impl<E, I, M> UnwindSafe for SourceBuffer<E, I, M> where
E: UnwindSafe,
I: UnwindSafe,
M: UnwindSafe,