Trait rsonpath::input::Input

source ·
pub trait Input: Sized {
    type BlockIterator<'i, 'r, const N: usize, R>: InputBlockIterator<'i, N, Block = Self::Block<'i, N>>
       where Self: 'i,
             R: InputRecorder<Self::Block<'i, N>> + 'r;
    type Block<'i, const N: usize>: InputBlock<'i, N>
       where Self: 'i;

    // Required methods
    fn iter_blocks<'i, 'r, R, const N: usize>(
        &'i self,
        recorder: &'r R
    ) -> Self::BlockIterator<'i, 'r, N, R>
       where R: InputRecorder<Self::Block<'i, N>>;
    fn seek_backward(&self, from: usize, needle: u8) -> Option<usize>;
    fn seek_forward<const N: usize>(
        &self,
        from: usize,
        needles: [u8; N]
    ) -> Result<Option<(usize, u8)>, InputError>;
    fn seek_non_whitespace_forward(
        &self,
        from: usize
    ) -> Result<Option<(usize, u8)>, InputError>;
    fn seek_non_whitespace_backward(&self, from: usize) -> Option<(usize, u8)>;
    fn find_member(
        &self,
        from: usize,
        member: &JsonString
    ) -> Result<Option<usize>, InputError>;
    fn is_member_match(
        &self,
        from: usize,
        to: usize,
        member: &JsonString
    ) -> bool;
}
Expand description

UTF-8 encoded bytes representing a JSON document that support block-by-block iteration and basic seeking procedures.

Required Associated Types§

source

type BlockIterator<'i, 'r, const N: usize, R>: InputBlockIterator<'i, N, Block = Self::Block<'i, N>> where Self: 'i, R: InputRecorder<Self::Block<'i, N>> + 'r

Type of the iterator used by iter_blocks, parameterized by the lifetime of source input and the size of the block.

source

type Block<'i, const N: usize>: InputBlock<'i, N> where Self: 'i

Type of the blocks returned by the BlockIterator.

Required Methods§

source

fn iter_blocks<'i, 'r, R, const N: usize>( &'i self, recorder: &'r R ) -> Self::BlockIterator<'i, 'r, N, R>where R: InputRecorder<Self::Block<'i, N>>,

Iterate over blocks of size N of the input. N has to be a power of two larger than 1.

source

fn seek_backward(&self, from: usize, needle: u8) -> Option<usize>

Search for an occurrence of needle in the input, starting from from and looking back. Returns the index of the first occurrence or None if the needle was not found.

source

fn seek_forward<const N: usize>( &self, from: usize, needles: [u8; N] ) -> Result<Option<(usize, u8)>, InputError>

Search for an occurrence of any of the needles in the input, starting from from and looking forward. Returns the index of the first occurrence and the needle found, or None if none of the needles were not found.

Errors

This function can read more data from the input if no relevant characters are found in the current buffer, which can fail.

source

fn seek_non_whitespace_forward( &self, from: usize ) -> Result<Option<(usize, u8)>, InputError>

Search for the first byte in the input that is not ASCII whitespace starting from from. Returns a pair: the index of first such byte, and the byte itself; or None if no non-whitespace characters were found.

Errors

This function can read more data from the input if no relevant characters are found in the current buffer, which can fail.

source

fn seek_non_whitespace_backward(&self, from: usize) -> Option<(usize, u8)>

Search for the first byte in the input that is not ASCII whitespace starting from from and looking back. Returns a pair: the index of first such byte, and the byte itself; or None if no non-whitespace characters were found.

source

fn find_member( &self, from: usize, member: &JsonString ) -> Result<Option<usize>, InputError>

Search the input for the first occurrence of member name member (comparing bitwise, including double quotes delimiters) starting from from. Returns the index of the first occurrence, or None if no occurrence was found.

This will also check if the leading double quote is not escaped by a backslash character, but will ignore any other structural properties of the input. In particular, the member might be found at an arbitrary depth.

Errors

This function can read more data from the input if no relevant characters are found in the current buffer, which can fail.

source

fn is_member_match(&self, from: usize, to: usize, member: &JsonString) -> bool

Decide whether the slice of input between from (inclusive) and to (exclusive) matches the member (comparing bitwise, including double quotes delimiters).

This will also check if the leading double quote is not escaped by a backslash character.

Implementors§

source§

impl Input for MmapInput

§

type BlockIterator<'a, 'r, const N: usize, R> = BorrowedBytesBlockIterator<'a, 'r, N, R> where R: InputRecorder<&'a [u8]> + 'r

§

type Block<'a, const N: usize> = &'a [u8]

source§

impl Input for OwnedBytes

§

type BlockIterator<'a, 'r, const N: usize, R> = BorrowedBytesBlockIterator<'a, 'r, N, R> where R: InputRecorder<&'a [u8]> + 'r

§

type Block<'a, const N: usize> = &'a [u8]

source§

impl<'a> Input for BorrowedBytes<'a>

§

type BlockIterator<'b, 'r, const N: usize, R> = BorrowedBytesBlockIterator<'b, 'r, N, R> where Self: 'b, R: InputRecorder<&'b [u8]> + 'r

§

type Block<'b, const N: usize> = &'b [u8] where Self: 'b

source§

impl<R: Read> Input for BufferedInput<R>

§

type BlockIterator<'a, 'r, const N: usize, IR> = BufferedInputBlockIterator<'a, 'r, R, IR, N> where Self: 'a, IR: InputRecorder<BufferedInputBlock<N>> + 'r

§

type Block<'a, const N: usize> = BufferedInputBlock<N> where Self: 'a