Reader

Struct Reader 

Source
pub struct Reader<'r> {
    pub index: usize,
    pub line: usize,
    pub column: usize,
    /* private fields */
}

Fields§

§index: usize§line: usize

location feature required
Line of current parsing point

§column: usize

location feature required
Column of current parsing point

Implementations§

Source§

impl<'r> Reader<'r>

Source

pub const fn new(buf: &'r [u8]) -> Self

Source

pub fn remaining(&self) -> &[u8]

Source

pub fn advance_by(&mut self, max: usize)

Advance by max bytes (or, if remaining bytes is shorter than max, read all remaining bytes)

Source

pub fn unwind_by(&mut self, max: usize)

Unwind the parsing point by max bytes (or, if already-read bytes is shorter than max, rewind all)

When "location" feature is activated, this may be less performant for some extensive input

Source

pub fn skip_while(&mut self, condition: impl Fn(&u8) -> bool)

Skip next byte while condition holds on it

Source

pub fn skip_whitespace(&mut self)

skip_while(u8::is_ascii_whitespace)

Source

pub fn read_while(&mut self, condition: impl Fn(&u8) -> bool) -> &'r [u8]

Read next byte while the condition holds on it

Source

pub fn read_until(&mut self, pattern: impl AsRef<[u8]>) -> &'r [u8]

Read through until the pattern comes in front of reader.

Source

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

Read next byte, or return None if the remaining bytes is empty

Source

pub fn next_if(&mut self, condition: impl Fn(&u8) -> bool) -> Option<u8>

Read next byte if the condition holds on it

Source

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

Peek next byte (without consuming)

Source

pub fn peek2(&self) -> Option<&u8>

Peek next byte of next byte (without consuming)

Source

pub fn peek3(&self) -> Option<&u8>

Peek next byte of next byte of next byte (without consuming)

Source

pub fn consume(&mut self, token: impl AsRef<[u8]>) -> Option<()>

Read token if the remaining bytes start with it

Source

pub fn consume_oneof<const N: usize>( &mut self, tokens: [impl AsRef<[u8]>; N], ) -> Option<usize>

Read the first token in tokens that matches the start with the remaining bytes, and returns the index of the (matched) token, or None if none matches

Source§

impl<'r> Reader<'r>

Source

pub fn read_camel(&mut self) -> Option<&'r str>

text feature required
Read a camelCase word like helloWorld, userID, … as &str if found

Source

pub fn read_snake(&mut self) -> Option<&'r str>

text feature required
Read a snake_case word like hello_world, user_id, … as &str if found

Source

pub fn read_kebab(&mut self) -> Option<&'r str>

text feature required
Read a kebeb-case word like hello-world, Content-Type, … as &str if found

Source

pub fn read_quoted_by(&mut self, left: u8, right: u8) -> Option<&'r [u8]>

text feature required
Read all bytes enclosed between left and right, then consume left, the bytes and right, and return the bytes.

Or, returns None if left or right is not found in remaining bytes.

Source

pub fn read_uint(&mut self) -> Option<usize>

text feature required
Read an unsigned integer literal like 42, 123 as usize if found

  • Panics if the integer is larger than usize::MAX
Source

pub fn read_int(&mut self) -> Option<isize>

text feature required
Read an integer literal like 42, -1111 as isize if found

  • Panics if not isize::MIN <= {the integer} <= isize::MAX

Auto Trait Implementations§

§

impl<'r> Freeze for Reader<'r>

§

impl<'r> RefUnwindSafe for Reader<'r>

§

impl<'r> Send for Reader<'r>

§

impl<'r> Sync for Reader<'r>

§

impl<'r> Unpin for Reader<'r>

§

impl<'r> UnwindSafe for Reader<'r>

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.