pub struct VarZeroVecComponents<'a, T: ?Sized, F> {
len: u32,
indices: &'a [u8],
things: &'a [u8],
marker: PhantomData<(&'a T, F)>,
}Expand description
A more parsed version of VarZeroSlice. This type is where most of the VarZeroVec
internal representation code lies.
This is basically an &'a [u8] to a zero copy buffer, but split out into
the buffer components. Logically this is capable of behaving as
a &'a [T::VarULE], but since T::VarULE is unsized that type does not actually
exist.
See VarZeroVecComponents::parse_bytes() for information on the internal invariants involved
Fields§
§len: u32The number of elements
indices: &'a [u8]The list of indices into the things slice
Since the first element is always at things[0], the first element of the indices array is for the second element
things: &'a [u8]The contiguous list of T::VarULEs
marker: PhantomData<(&'a T, F)>Implementations§
Source§impl<'a, T: VarULE + ?Sized, F: VarZeroVecFormat> VarZeroVecComponents<'a, T, F>
impl<'a, T: VarULE + ?Sized, F: VarZeroVecFormat> VarZeroVecComponents<'a, T, F>
Sourcepub fn parse_bytes(slice: &'a [u8]) -> Result<Self, VarZeroVecFormatError>
pub fn parse_bytes(slice: &'a [u8]) -> Result<Self, VarZeroVecFormatError>
Construct a new VarZeroVecComponents, checking invariants about the overall buffer size:
- There must be either zero or at least four bytes (if four, this is the “length” parsed as a usize)
- There must be at least
4*(length - 1) + 4bytes total, to form the arrayindicesof indices 0..indices[0]must index into a valid section ofthings(the data afterindices), such that it parses to aT::VarULEindices[i - 1]..indices[i]must index into a valid section ofthings(the data afterindices), such that it parses to aT::VarULEindices[len - 2]..things.len()must index into a valid section ofthings, such that it parses to aT::VarULE
Sourcepub fn parse_bytes_with_length(
len: u32,
slice: &'a [u8],
) -> Result<Self, VarZeroVecFormatError>
pub fn parse_bytes_with_length( len: u32, slice: &'a [u8], ) -> Result<Self, VarZeroVecFormatError>
Construct a new VarZeroVecComponents, checking invariants about the overall buffer size:
- There must be at least
4*lenbytes total, to form the arrayindicesof indices. indices[i]..indices[i+1]must index into a valid section ofthings(the data afterindices), such that it parses to aT::VarULEindices[len - 1]..things.len()must index into a valid section ofthings, such that it parses to aT::VarULE
Sourcepub unsafe fn from_bytes_unchecked(slice: &'a [u8]) -> Self
pub unsafe fn from_bytes_unchecked(slice: &'a [u8]) -> Self
Construct a VarZeroVecComponents from a byte slice that has previously
successfully returned a VarZeroVecComponents when passed to
VarZeroVecComponents::parse_bytes(). Will return the same
object as one would get from calling VarZeroVecComponents::parse_bytes().
§Safety
The bytes must have previously successfully run through
VarZeroVecComponents::parse_bytes()
Sourcepub unsafe fn from_bytes_unchecked_with_length(
len: u32,
slice: &'a [u8],
) -> Self
pub unsafe fn from_bytes_unchecked_with_length( len: u32, slice: &'a [u8], ) -> Self
Construct a VarZeroVecComponents from a byte slice that has previously
successfully returned a VarZeroVecComponents when passed to
VarZeroVecComponents::parse_bytes(). Will return the same
object as one would get from calling VarZeroVecComponents::parse_bytes().
§Safety
The len,bytes must have previously successfully run through
VarZeroVecComponents::parse_bytes_with_length()
Sourcepub fn get(self, idx: usize) -> Option<&'a T>
pub fn get(self, idx: usize) -> Option<&'a T>
Get the idx’th element out of this slice. Returns None if out of bounds.
Sourcepub(crate) unsafe fn get_unchecked(self, idx: usize) -> &'a T
pub(crate) unsafe fn get_unchecked(self, idx: usize) -> &'a T
Get the idx’th element out of this slice. Does not bounds check.
Safety:
idxmust be in bounds (idx < self.len())
Sourcepub(crate) unsafe fn get_things_range(self, idx: usize) -> Range<usize>
pub(crate) unsafe fn get_things_range(self, idx: usize) -> Range<usize>
Get the range in things for the element at idx. Does not bounds check.
Safety:
idxmust be in bounds (idx < self.len())
Sourcepub(crate) unsafe fn get_indices_size(self) -> usize
pub(crate) unsafe fn get_indices_size(self) -> usize
Get the size, in bytes, of the indices array
Sourcefn check_indices_and_things(self) -> Result<(), VarZeroVecFormatError>
fn check_indices_and_things(self) -> Result<(), VarZeroVecFormatError>
Check the internal invariants of VarZeroVecComponents:
indices[i]..indices[i+1]must index into a valid section ofthings, such that it parses to aT::VarULEindices[len - 1]..things.len()must index into a valid section ofthings, such that it parses to aT::VarULEindicesis monotonically increasing
This method is NOT allowed to call any other methods on VarZeroVecComponents since all other methods
assume that the slice has been passed through Self::check_indices_and_things
Sourcepub fn iter(self) -> VarZeroSliceIter<'a, T, F> ⓘ
pub fn iter(self) -> VarZeroSliceIter<'a, T, F> ⓘ
Create an iterator over the Ts contained in VarZeroVecComponents
pub fn to_vec(self) -> Vec<Box<T>>
fn indices_slice(&self) -> &'a [F::Index]
pub(crate) fn dump(&self) -> String
Source§impl<'a, T, F> VarZeroVecComponents<'a, T, F>
impl<'a, T, F> VarZeroVecComponents<'a, T, F>
Sourcepub fn binary_search(&self, needle: &T) -> Result<usize, usize>
pub fn binary_search(&self, needle: &T) -> Result<usize, usize>
Binary searches a sorted VarZeroVecComponents<T> for the given element. For more information, see
the primitive function binary_search.
pub fn binary_search_in_range( &self, needle: &T, range: Range<usize>, ) -> Option<Result<usize, usize>>
Source§impl<'a, T, F> VarZeroVecComponents<'a, T, F>
impl<'a, T, F> VarZeroVecComponents<'a, T, F>
Sourcepub fn binary_search_by(
&self,
predicate: impl FnMut(&T) -> Ordering,
) -> Result<usize, usize>
pub fn binary_search_by( &self, predicate: impl FnMut(&T) -> Ordering, ) -> Result<usize, usize>
Binary searches a sorted VarZeroVecComponents<T> for the given predicate. For more information, see
the primitive function binary_search_by.