SliceLexer

Struct SliceLexer 

Source
pub struct SliceLexer<'a> { /* private fields */ }
Expand description

JSON lexer from a shared byte slice.

Implementations§

Source§

impl<'a> SliceLexer<'a>

Source

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

Create a new slice lexer.

A fast way to obtain the contents of a file as &[u8] is memory mapping; see for example the memmap2 crate.

Source

pub fn as_slice(&self) -> &'a [u8]

Return remaining input as a subslice of the original data.

This can be used to find the place where an error occurred.

Trait Implementations§

Source§

impl<'a> LexAlloc for SliceLexer<'a>

Available on crate feature alloc only.
Source§

type Str = Cow<'a, str>

The type of string that we are lexing into.
Source§

fn str_string(&mut self) -> Result<Self::Str, Error>

Lex a JSON string to a Rust string.
Source§

impl<'a> LexWrite for SliceLexer<'a>

Source§

type Num = &'a str

String type to save numbers as.
Source§

fn num_bytes( &mut self, bytes: &mut Self::Bytes, prefix: &[u8], ) -> Result<Parts, Error>

Write a prefix and a number to bytes and save its parts. Read more
Source§

fn num_string(&mut self, prefix: &str) -> Result<(Self::Num, Parts), Error>

Write a prefix and a number to a string and save its parts.
Source§

impl<'a> Read for SliceLexer<'a>

Source§

fn strip_prefix(&mut self, s: &[u8]) -> bool

Return true if the given byte sequence is a prefix of the input. Read more
Source§

fn skip_until(&mut self, stop: impl FnMut(u8) -> bool)

Ignore input until stop yields true.
Source§

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

Take the next byte.
Source§

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

Peek at the next byte.
Source§

fn foreach_until(&mut self, f: impl FnMut(u8), stop: impl FnMut(u8) -> bool)

Run a function on current input until a certain condition is fulfilled.
Source§

impl<'a> Write for SliceLexer<'a>

Source§

type Bytes = &'a [u8]

Type of bytes to write to.
Source§

fn write_until(&mut self, bytes: &mut &'a [u8], stop: impl FnMut(u8) -> bool)

Write input to bytes until stop yields true. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SliceLexer<'a>

§

impl<'a> RefUnwindSafe for SliceLexer<'a>

§

impl<'a> Send for SliceLexer<'a>

§

impl<'a> Sync for SliceLexer<'a>

§

impl<'a> Unpin for SliceLexer<'a>

§

impl<'a> UnwindSafe for SliceLexer<'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> 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> Lex for T
where T: Read,

Source§

fn low_surrogate(&mut self, high: u16) -> Result<u32, Error>

Given a high surrogate, parse a low surrogate and combine them.
Source§

fn escape(&mut self, c: u8) -> Result<char, Error>

Convert an escape sequence, such as \n or \u0009 (without leading \), to a char, potentially reading more.
Source§

fn hex<T: From<u8> + Shl<Output = T> + Add<Output = T>>( &mut self, ) -> Result<T, Error>

Parse a hexadecimal number into an unsigned integer type T. Read more
Source§

impl<T> Lex for T
where T: Read,

Source§

fn digits_foreach(&mut self, f: impl FnMut(u8)) -> usize

Perform f for every digit read and return the number of read bytes.
Source§

fn digits1_foreach(&mut self, f: impl FnMut(u8)) -> Result<NonZeroUsize, Error>

Run function for every digit, fail if no digit encountered.
Source§

fn num_foreach(&mut self, f: impl FnMut(u8)) -> Result<Parts, Error>

Run function for each character of a number.
Source§

fn num_ignore(&mut self) -> Result<Parts, Error>

Lex a number and ignore its contents, saving only its parts.
Source§

impl<T> Lex for T
where T: Lex,

Source§

fn str_ignore(&mut self) -> Result<(), Error>

Read a string without saving it.
Source§

fn str_foreach(&mut self, f: impl FnMut(u8)) -> Result<(), Error>

Run a function for every character of the string.
Source§

impl<T> Lex for T
where T: Read,

Source§

fn eat_whitespace(&mut self)

Skip input until the earliest non-whitespace character.
Source§

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

Skip whitespace and peek at the following character.
Source§

fn null_or_bool(&mut self) -> Option<Option<bool>>

Parse a JSON token starting with a letter. Read more
Source§

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

Take next character, discard it, and return mutable handle to lexer. Read more
Source§

fn expect( &mut self, pf: impl FnOnce(&mut Self) -> Option<u8>, expect: u8, ) -> Option<()>

Peek at next character, and discard it if it matches the expected character. Read more
Source§

fn seq<E: From<Expect>, PF, F>( &mut self, end: u8, pf: PF, f: F, ) -> Result<(), E>
where PF: FnMut(&mut Self) -> Option<u8>, F: FnMut(u8, &mut Self) -> Result<(), E>,

Execute f for every item in the comma-separated sequence until end.
Source§

fn exactly_one<T, E: From<Expect>, PF, F>( &mut self, pf: PF, f: F, ) -> Result<T, E>
where PF: FnMut(&mut Self) -> Option<u8>, F: FnOnce(u8, &mut Self) -> Result<T, E>,

Parse once using given function and assure that the function has consumed all tokens.
Source§

impl<T> LexWrite for T
where T: Read + Write,

Source§

fn str_bytes(&mut self, bytes: &mut Self::Bytes) -> Result<(), Error>

Read a string to bytes, copying escape sequences one-to-one.
Source§

fn str_fold<E: From<Error>, T>( &mut self, out: T, on_string: impl Fn(&mut Self::Bytes, &mut T) -> Result<(), E>, on_escape: impl Fn(&mut Self, &mut T) -> Result<(), E>, ) -> Result<T, E>

Lex a string by executing on_string on every string and on_bytes on every escape sequence.
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.
Source§

impl<T> Lex for T
where T: Lex + Lex + Lex,

Source§

impl<T> LexAlloc for T
where T: LexWrite + LexAlloc,

Source§

impl<T> LexWrite for T
where T: Lex + LexWrite + LexWrite,