Scanner

Struct Scanner 

Source
pub struct Scanner<T, R>
where T: Read + Sized, R: Clone,
{ /* private fields */ }
Available on crate feature std only.
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>

Source

pub fn new(input: T, delimiters: &[Token<R>]) -> Self

Creates a scanner with the default buffer capacity, 8KB

Source

pub fn with_max_lookahead( input: T, max_buffer: usize, delimiters: &[Token<R>], ) -> Self

Creates a scanner with the specified buffer capacity

Source

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

Source

pub fn read_next(&mut self) -> Result<ReadToken<'_, R>, Error>

Source

pub fn consume(&mut self, len: usize)

Source

pub fn take_back(self) -> Buffer<BufReader<T>>

Source§

impl<T: Read + Sized> Scanner<T, LineEnding>

Source

pub fn new_lf(input: T) -> Self

Source

pub fn new_crlf(input: T) -> Self

Source

pub fn new_cr(input: T) -> Self

Auto Trait Implementations§

§

impl<T, R> Freeze for Scanner<T, R>
where T: Freeze,

§

impl<T, R> RefUnwindSafe for Scanner<T, R>

§

impl<T, R> Send for Scanner<T, R>
where T: Send, R: Send,

§

impl<T, R> Sync for Scanner<T, R>
where T: Sync, R: Sync,

§

impl<T, R> Unpin for Scanner<T, R>
where T: Unpin, R: Unpin,

§

impl<T, R> UnwindSafe for Scanner<T, R>
where T: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> MaybeInto<U> for T
where U: MaybeFrom<T>,

Source§

fn maybe_into(self) -> Option<U>

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.