Struct SliceReader

Source
pub struct SliceReader<'buf> { /* private fields */ }
Expand description

Wraps a slice of bytes with a movable cursor.

The cursor is moved when parsing Patterns.

Implementations§

Source§

impl<'b> SliceReader<'b>

Source

pub fn new(input: &'b [u8]) -> Self

Creates a new reader from the given slice

Source

pub fn parse(&mut self, pattern: impl Pattern) -> Option<&'b [u8]>

Tests pattern against the elements at the reader’s current position.

If the pattern matches, the cursor is moved, and the matching elements are returned.

Source

pub fn iter<'i, P: Pattern>( &'i mut self, pattern: P, ) -> ItemMatchIterMut<'i, 'b, P>

Returns an iterator that repeatedly tests pattern against the input until it stops matching.

Advancing the iterator also advances the cursor.

Source

pub fn parse_delimited<L, R>(&mut self, left: L, right: R) -> Option<&'b [u8]>
where L: Pattern, R: Pattern,

Extracts the slice delimited by the given patterns.

The cursor is set to right after the right match, and the bytes between the left and right matches are returned.

Returns None if left does not match. Returns None if no match for right is found after left

Source

pub fn take_until(&mut self, pattern: impl Pattern) -> Option<&'b [u8]>

Advances the cursor until the pattern matches.

The cursor is set right before the match, and the elements leading up to the match are returned.

Returns None if the end of input is reached before pattern can be matched.

Source

pub fn accept(&mut self, pattern: impl Pattern) -> bool

Tests the pattern against the elements at the reader’s current position.

If the pattern matches, the cursor is moved and the function returns true.

Source

pub fn peek(&mut self, pattern: impl Pattern) -> bool

Like SliceReader::accept, but the cursor is not moved after a successful match.

Source

pub fn position(&self) -> usize

Returns the cursor’s offset from the start of the input.

Source

pub fn eof(&self) -> bool

Returns true if the cursor is at the end of the input.

Source

pub fn get_ref(&self) -> &'b [u8]

Returns a reference to the underlying slice

Auto Trait Implementations§

§

impl<'buf> Freeze for SliceReader<'buf>

§

impl<'buf> RefUnwindSafe for SliceReader<'buf>

§

impl<'buf> Send for SliceReader<'buf>

§

impl<'buf> Sync for SliceReader<'buf>

§

impl<'buf> Unpin for SliceReader<'buf>

§

impl<'buf> UnwindSafe for SliceReader<'buf>

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> 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.