Struct rsonpath::input::borrowed::BorrowedBytes
source · pub struct BorrowedBytes<'a> { /* private fields */ }
Expand description
Input wrapping a borrowed [[u8]
] buffer.
Implementations§
source§impl<'a> BorrowedBytes<'a>
impl<'a> BorrowedBytes<'a>
sourcepub unsafe fn new(bytes: &'a [u8]) -> Self
pub unsafe fn new(bytes: &'a [u8]) -> Self
Create a new instance of BorrowedBytes
wrapping the given buffer.
Safety
The buffer must satisfy all invariants of BorrowedBytes
,
since it is not copied or modified. It must:
- have length divisible by
MAX_BLOCK_SIZE
(the function checks this); - be aligned to
MAX_BLOCK_SIZE
.
The latter condition cannot be reliably checked. Violating it may result in memory errors where the engine relies on proper alignment.
Panics
If bytes.len()
is not divisible by MAX_BLOCK_SIZE
.
sourcepub fn to_owned(&self) -> OwnedBytes
pub fn to_owned(&self) -> OwnedBytes
Copy the bytes to an OwnedBytes
instance.
Trait Implementations§
source§impl<'a> AsRef<[u8]> for BorrowedBytes<'a>
impl<'a> AsRef<[u8]> for BorrowedBytes<'a>
source§impl<'a> From<&BorrowedBytes<'a>> for OwnedBytes
impl<'a> From<&BorrowedBytes<'a>> for OwnedBytes
source§fn from(value: &BorrowedBytes<'_>) -> Self
fn from(value: &BorrowedBytes<'_>) -> Self
Converts to this type from the input type.
source§impl<'a> Input for BorrowedBytes<'a>
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 BlockIterator<'b, 'r, const N: usize, R> = BorrowedBytesBlockIterator<'b, 'r, N, R> where Self: 'b, R: InputRecorder<&'b [u8]> + 'r
Type of the iterator used by
iter_blocks
, parameterized
by the lifetime of source input and the size of the block.§type Block<'b, const N: usize> = &'b [u8]
where
Self: 'b
type Block<'b, const N: usize> = &'b [u8] where Self: 'b
Type of the blocks returned by the
BlockIterator
.source§fn iter_blocks<'b, 'r, R, const N: usize>(
&'b self,
recorder: &'r R
) -> Self::BlockIterator<'b, 'r, N, R>where
R: InputRecorder<&'b [u8]>,
fn iter_blocks<'b, 'r, R, const N: usize>( &'b self, recorder: &'r R ) -> Self::BlockIterator<'b, 'r, N, R>where R: InputRecorder<&'b [u8]>,
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>
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>
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. Read moresource§fn seek_non_whitespace_forward(
&self,
from: usize
) -> Result<Option<(usize, u8)>, InputError>
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. Read moresource§fn seek_non_whitespace_backward(&self, from: usize) -> Option<(usize, u8)>
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>
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. Read moresource§fn is_member_match(&self, from: usize, to: usize, member: &JsonString) -> bool
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). Read moreAuto Trait Implementations§
impl<'a> RefUnwindSafe for BorrowedBytes<'a>
impl<'a> Send for BorrowedBytes<'a>
impl<'a> Sync for BorrowedBytes<'a>
impl<'a> Unpin for BorrowedBytes<'a>
impl<'a> UnwindSafe for BorrowedBytes<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more