Struct ReadToken

Source
pub struct ReadToken<'a> {
    pub src: &'a str,
    pub offset: usize,
}
Expand description

Stores the state of parsing.

Fields§

§src: &'a str

Source.

§offset: usize

Byte offset.

Implementations§

Source§

impl<'a> ReadToken<'a>

Source

pub fn new(src: &'a str, offset: usize) -> ReadToken<'a>

Creates a new ReadToken. The offset is in bytes.

Source

pub fn consume(self, n: usize) -> ReadToken<'a>

Consumes n bytes.

Source

pub fn raw_string(&self, n: usize) -> String

Reads a raw string.

Source

pub fn lines<F>(&self, f: F) -> Result<Range, Range>
where F: FnMut(&ReadToken<'_>) -> Option<Range>,

Read lines until closure returns None. Returns Ok(range) of the successful read lines. Returns Err(range) when expected new line.

Source

pub fn subtract(&self, rhs: &Self) -> Range

Returns the difference in offset.

Source

pub fn start(&self) -> Range

Returns an empty range at current offset.

Source

pub fn peek(&self, n: usize) -> Range

Peek a number of bytes ahead.

Source

pub fn tag(&self, tag: &str) -> Option<Range>

Reads an expected tag, returns character range and new state. Returns old state when fail to match tag.

Source

pub fn until_any_or_whitespace(&self, any: &str) -> (Range, Option<usize>)

Reads a token until any character in string or whitespace. Returns (range, None) if stopping at whitespace or end of text. Returns (range, Some(x)) if stopping at a character.

Source

pub fn until_any(&self, any: &str) -> (Range, Option<usize>)

Reads token until any character in string. Returns (new_state, range, None) if stopping at end of text. Returns (new_state, range, Some(x)) if stopping at a character.

Source

pub fn whitespace(&self) -> Range

Reads whitespace.

Source

pub fn string(&self) -> Option<Range>

Reads string with character escapes.

Source

pub fn number(&self, settings: &NumberSettings) -> Option<Range>

Reads number.

Source

pub fn parse_string(&self, n: usize) -> Result<String, Range<ParseStringError>>

Parses string into a real string according to the JSON standard.

Assumes the string starts and ends with double-quotes. n is the number of bytes to read and must be at least 2, because the string is surrounded by quotes.

Source

pub fn parse_number( &self, settings: &NumberSettings, n: usize, ) -> Result<f64, ParseNumberError>

Parses number from n bytes.

Trait Implementations§

Source§

impl<'a> Clone for ReadToken<'a>

Source§

fn clone(&self) -> ReadToken<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ReadToken<'a>

Source§

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

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

impl<'a> Copy for ReadToken<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for ReadToken<'a>

§

impl<'a> RefUnwindSafe for ReadToken<'a>

§

impl<'a> Send for ReadToken<'a>

§

impl<'a> Sync for ReadToken<'a>

§

impl<'a> Unpin for ReadToken<'a>

§

impl<'a> UnwindSafe for ReadToken<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.