Struct flussab::text::LineReader [−][src]
Wraps a ByteReader
to count track lines.
For performance reasons, counting lines isn’t done automatically. Instead, you are expected to
read directly from the underlying ByteReader
and to call
line_at_offset
whenever you advance past the end of a line.
If this is done, give_up
can be used to generate SyntaxError
’s that contain
the source location and display the line containing the syntax error.
Fields
reader: ByteReader<'a>
The wrapped ByteReader
.
line: usize
The current line, starting at 1
.
line_start: usize
The position where the current line starts, as returned by ByteReader::position
.
Implementations
impl<'a> LineReader<'a>
[src]
pub fn new(reader: ByteReader<'a>) -> Self
[src]
Creates a LineReader
assuming line 1 starts at the current position of the passed
ByteReader
.
pub fn reader(&mut self) -> &mut ByteReader<'a>
[src]
Returns a mutable reference to the ByteReader
.
While the reader
field is directly accessible, using this method can be more convenient if
a mutable reference is needed.
pub fn line_at_offset(&mut self, offset: usize)
[src]
Advance the line counter and record the start of a new line.
The offset
value is relative to the current position()
as
returned by self.reader
.
pub fn give_up<E>(&mut self, msg: impl Into<String>) -> E where
E: From<Error> + From<SyntaxError>,
[src]
E: From<Error> + From<SyntaxError>,
Generate a syntax error at the current reader position.
pub fn give_up_at<E>(&mut self, position: usize, msg: impl Into<String>) -> E where
E: From<Error> + From<SyntaxError>,
[src]
E: From<Error> + From<SyntaxError>,
Generate a syntax error at position
.
This assumes that position
is on the current line, otherwise the resulting LineColumn
will be incorrect.
Auto Trait Implementations
impl<'a> !RefUnwindSafe for LineReader<'a>
impl<'a> !Send for LineReader<'a>
impl<'a> !Sync for LineReader<'a>
impl<'a> Unpin for LineReader<'a>
impl<'a> !UnwindSafe for LineReader<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,