Struct byte_parser::Parser

source ·
pub struct Parser<'s> { /* private fields */ }
Expand description

ParseIterator implementation for a slice.

Implementations§

source§

impl<'s> Parser<'s>

source

pub fn new(slice: &'s [u8]) -> Self

Creates a new Parser from a slice.

Trait Implementations§

source§

impl<'s> Debug for Parser<'s>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'s> ParseIterator<'s> for Parser<'s>

§

type PointInTime = ParserPointInTime

The type that is used to store information about the current position.
source§

fn slice(&self) -> &'s [u8]

Returns the full underlying slice.
source§

fn pit(&self) -> Self::PointInTime

Returns the current position. Should be used in combination with restore_pit.
source§

fn restore_pit(&mut self, pit: Self::PointInTime)

Restore to a given position. Read more
source§

fn advance(&mut self) -> Option<()>

Advances the internal position.
source§

fn recorder(&self) -> Option<&Recorder>

Returns a Recorder if recording was started.
source§

unsafe fn is_valid_utf8() -> bool

Safety Read more
source§

fn advance_if<F>(&mut self, advance_if: F) -> Option<bool>where F: FnOnce(&u8) -> bool,

Advances if advance_if returns true. Returns None if the iterator is empty.
source§

fn byte(&self) -> Option<u8>

Returns the current byte if it exists.
source§

fn next(&mut self) -> Option<u8>

Returns the next byte if it exists and advances the internal position.
source§

fn next_if<F>(&mut self, next_if: F) -> Option<u8>where F: FnOnce(&u8) -> bool,

Advances one if next_if returns true. Returns None if did not advance.
source§

fn peek(&mut self) -> Option<u8>

Returns the next byte without advancing the internal position.
source§

fn peek_len(&mut self, len: usize) -> Option<&'s [u8]>where Self: Sized,

Returns the next x bytes without advancing the internal position.
source§

fn peek_at(&mut self, pos: usize) -> Option<u8>

Tries to get the byte at the given position, without advancing.
source§

fn ignore_byte(&mut self, byte: u8) -> IgnoreByte<'_, Self>where Self: Sized,

Skips a given byte when calling next. Read more
source§

fn while_byte_fn<F>(&mut self, f: F) -> WhileByteFn<'_, Self, F>where Self: Sized, F: Fn(&u8) -> bool,

Advances while the function returns true.
source§

fn consume(&mut self) -> &mut Self

Consumes until the iterator is empty. Meaning that advance returns None.
source§

fn consume_and_count(&mut self) -> usize

Consumes until the iterator is empty, and returns how many times advance got called.
source§

fn consume_len(&mut self, len: usize) -> Result<&mut Self, usize>

Consumes a given length. Returns how much was consumed if could not consume all.
source§

fn consume_at_least(&mut self, len: usize) -> Result<&mut Self, usize>

Consumes until the iterator is empty. Returns Err(len) if could not consume len.
source§

fn consume_at_least_and_count(&mut self, len: usize) -> Result<usize, usize>

Consumes until the iterator is empty, returning how much was consumed. Returns Err(len) if could not consume len.
source§

fn consume_while_byte_fn<F>(&mut self, f: F) -> &mut Selfwhere Self: Sized, F: Fn(&u8) -> bool,

Consumes while the function returns true.
source§

fn consume_while_byte(&mut self, byte: u8) -> &mut Selfwhere Self: Sized,

Consumes while a give byte is returned.
source§

fn split_on_byte(&mut self, byte: u8) -> SplitOnByte<'_, Self>where Self: Sized,

Splits the iterator at a given byte. Read more
source§

fn count_byte(&mut self, byte: u8) -> usizewhere Self: Sized,

source§

fn record(&mut self) -> RecordIter<'_, Self>where Self: Sized,

Starts a new Recorder which starts recording at this position.
source§

fn to_slice(&self) -> &'s [u8]

Returns a slice from the start of recording until now. Read more
source§

unsafe fn to_str_unchecked(&self) -> &'s str

Returns a str from the start of recording until the current position without checking if the data is valid utf8. Read more
source§

fn to_str(&self) -> &'s str

Returns a str from the start of recording until the current position. Read more
source§

fn try_to_str(&self) -> Result<&'s str, Utf8Error>

Returns a str from the start of recording until the current position. Read more
source§

fn consume_to_slice(&mut self) -> &'s [u8]

Consumes the iterator and then returns a slice from the start of recording until the current position. Read more
source§

unsafe fn consume_to_str_unchecked(&mut self) -> &'s str

Consumes the iterator and then returns a str from the start of recording until the current position. Without checking if the underlying data is valid utf8. Read more
source§

fn consume_to_str(&mut self) -> &'s str

Consumes the iterator and then returns a str from the start of recording until the current position. Read more
source§

fn consume_try_to_str(&mut self) -> Result<&'s str, Utf8Error>

Consumes the iterator and then returns a str from the start of recording until the current position if the data is valid utf8. Read more
source§

fn expect_byte_fn<F>(&mut self, f: F) -> Result<&mut Self, Option<u8>>where F: Fn(u8) -> bool,

Returns &mut Self if the function returns true on the next byte. Else returns the byte that was received.
source§

fn expect_byte(&mut self, byte: u8) -> Result<&mut Self, Option<u8>>

Returns &mut Self if the function byte is equal to the next byte. Else returns the actual byte that was received.
source§

fn expect_none(&mut self) -> Result<&mut Self, u8>

Returns &mut Self if the end was reached (next returns None).
source§

fn stop(&mut self) -> Stop<'_, Self>where Self: Sized,

Returns a ParseIterator that always returns None. Read more

Auto Trait Implementations§

§

impl<'s> RefUnwindSafe for Parser<'s>

§

impl<'s> Send for Parser<'s>

§

impl<'s> Sync for Parser<'s>

§

impl<'s> Unpin for Parser<'s>

§

impl<'s> UnwindSafe for Parser<'s>

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.