Trait Input

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

    // Required methods
    fn leading_padding_len(&self) -> usize;
    fn trailing_padding_len(&self) -> usize;
    fn iter_blocks<'i, 'r, R, const N: usize>(
        &'i self,
        recorder: &'r R,
    ) -> Self::BlockIterator<'i, 'r, R, N>
       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)>, Self::Error>;
    fn seek_non_whitespace_forward(
        &self,
        from: usize,
    ) -> Result<Option<(usize, u8)>, Self::Error>;
    fn seek_non_whitespace_backward(&self, from: usize) -> Option<(usize, u8)>;
    fn is_member_match(
        &self,
        from: usize,
        to: usize,
        member: &StringPattern,
    ) -> Result<bool, Self::Error>;

    // Provided method
    fn len_hint(&self) -> Option<usize> { ... }
}
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, R, const N: usize>: InputBlockIterator<'i, N, Block = Self::Block<'i, N>, Error = Self::Error> 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 Error: Into<InputError>

Type of errors that can occur when operating on this Input.

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 leading_padding_len(&self) -> usize

Return the length of the padding added at the start of the input.

This depends on the particular Input implementation, and may be zero. In any case the length of the entire input should be equivalent to the length of the source plus leading_padding_len plus trailing_padding_len.

Source

fn trailing_padding_len(&self) -> usize

Return the length of the padding added at the end of the input.

This depends on the particular Input implementation, and may be zero. In any case the length of the entire input should be equivalent to the length of the source plus leading_padding_len plus trailing_padding_len.

Source

fn iter_blocks<'i, 'r, R, const N: usize>( &'i self, recorder: &'r R, ) -> Self::BlockIterator<'i, 'r, R, N>
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)>, Self::Error>

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)>, Self::Error>

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 is_member_match( &self, from: usize, to: usize, member: &StringPattern, ) -> Result<bool, Self::Error>

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.

§Errors

This function can read more data from the input if to falls beyond the range that was already read, and the read operation can fail.

Provided Methods§

Source

fn len_hint(&self) -> Option<usize>

Return the length of the entire input, if known.

This is meant to be used merely as a hint. There are Input implementations that may not be able to know the entire length a priori, and they should return None.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Input for BorrowedBytes<'_>

Source§

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

Source§

type Error = Infallible

Source§

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

Source§

impl Input for MmapInput

Source§

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

Source§

type Error = Infallible

Source§

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

Source§

impl<B> Input for OwnedBytes<B>
where B: Borrow<[u8]>,

Source§

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

Source§

type Error = Infallible

Source§

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

Source§

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

Source§

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

Source§

type Error = InputError

Source§

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