Struct irox_tools::scanner::Scanner
source · pub struct Scanner<T, R>{ /* private fields */ }Expand description
A Scanner is a forward lookahead struct that scans through an stream of data looking for the indicated tokens.
The amount of possible forward lookahead is specified by the internal buffer
size of the BufReader
Implementations§
source§impl<T: Read + Sized, R: Clone> Scanner<T, R>
impl<T: Read + Sized, R: Clone> Scanner<T, R>
sourcepub fn new(input: T, delimiters: &[Token<R>]) -> Self
pub fn new(input: T, delimiters: &[Token<R>]) -> Self
Creates a scanner with the default buffer capacity, 8KB
sourcepub fn with_max_lookahead(
input: T,
max_buffer: usize,
delimiters: &[Token<R>]
) -> Self
pub fn with_max_lookahead( input: T, max_buffer: usize, delimiters: &[Token<R>] ) -> Self
Creates a scanner with the specified buffer capacity
sourcepub fn scan_until_next(&mut self) -> Result<FoundToken<'_, R>, Error>
pub fn scan_until_next(&mut self) -> Result<FoundToken<'_, R>, Error>
Scans through the buffer, looking for the specified token. Returns the
number of bytes in the stream needed to position the cursor to JUST BEFORE
the token. I.E., after calling read_exact(scan_until()), the next
call to read() will return the token itself.
Returns Ok(N) if it found the token in the input stream, or hit the end of the buffer without finding the token
Returns Ok(None) if there are no additional characters to read in the buffer - we’ve hit EOF.
Returns Err(e) if there’s an error reading from the underlying stream
pub fn read_next(&mut self) -> Result<ReadToken<'_, R>, Error>
Trait Implementations§
source§impl<T: Read + Sized, R: Clone> BufRead for Scanner<T, R>
impl<T: Read + Sized, R: Clone> BufRead for Scanner<T, R>
source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
source§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amt bytes have been consumed from the buffer,
so they should no longer be returned in calls to read. Read moresource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left)Read has any data left to be read. Read moresource§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
bufread_skip_until)byte or EOF is reached. Read more1.0.0 · source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA byte) is reached, and append
them to the provided String buffer. Read moresource§impl<T: Read + Sized, R: Clone> Read for Scanner<T, R>
impl<T: Read + Sized, R: Clone> Read for Scanner<T, R>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read moresource§impl<T: Read + Sized + Seek, R: Clone> Seek for Scanner<T, R>
impl<T: Read + Sized + Seek, R: Clone> Seek for Scanner<T, R>
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)