pub struct Scanner<S: Splitter> { /* private fields */ }
Expand description

Like a BufReader but with a growable buffer. Successive calls to the scan method will step through the ‘tokens’ of a file, skipping the bytes between the tokens.

Scanning stops unrecoverably at EOF, the first I/O error, or a token too large to fit in the buffer. When a scan stops, the reader may have advanced arbitrarily far past the last token.

Implementations§

source§

impl<S: Splitter> Scanner<S>

source

pub fn new(splitter: S) -> Scanner<S>

source

pub fn line(&self) -> u64

Current line number

source

pub fn column(&self) -> usize

Current column number (byte offset, not char offset)

source

pub fn splitter(&self) -> &S

source

pub fn mark(&mut self)

source

pub fn reset_to_mark(&mut self)

source

pub fn reset(&mut self)

Reset the scanner such that it behaves as if it had never been used.

source§

impl<S: Splitter> Scanner<S>

source

pub fn scan<'input>( &mut self, input: &'input [u8] ) -> Result<(usize, Option<(&'input [u8], S::TokenType)>, usize), S::Error>

Advance the Scanner to next token. Return the token as a byte slice. Return None when the end of the input is reached. Return any error that occurs while reading the input.

Trait Implementations§

source§

impl<S: Splitter> Debug for Scanner<S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> RefUnwindSafe for Scanner<S>where S: RefUnwindSafe,

§

impl<S> Send for Scanner<S>where S: Send,

§

impl<S> Sync for Scanner<S>where S: Sync,

§

impl<S> Unpin for Scanner<S>where S: Unpin,

§

impl<S> UnwindSafe for Scanner<S>where S: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.