pub struct VarZeroVecComponents<'a, T: ?Sized, F> {
len: u32,
indices: &'a [u8],
things: &'a [u8],
entire_slice: &'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_byte_slice() for information on the internal invariants involved
Fields§
§len: u32The number of elements
indices: &'a [u8]The list of indices into the things slice
things: &'a [u8]The contiguous list of T::VarULEs
entire_slice: &'a [u8]The original slice this was constructed from
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_byte_slice(slice: &'a [u8]) -> Result<Self, ZeroVecError>
pub fn parse_byte_slice(slice: &'a [u8]) -> Result<Self, ZeroVecError>
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 + 4bytes total, to form the arrayindicesof indices 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::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_byte_slice(). Will return the same
object as one would get from calling VarZeroVecComponents::parse_byte_slice().
§Safety
The bytes must have previously successfully run through
VarZeroVecComponents::parse_byte_slice()
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())
Sourceunsafe fn get_things_range(self, idx: usize) -> Range<usize>
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_range(self, idx: usize) -> Range<usize>
pub(crate) unsafe fn get_range(self, idx: usize) -> Range<usize>
Get the range in entire_slice for the element at idx. Does not bounds check.
Safety:
idxmust be in bounds (idx < self.len())
Sourcefn check_indices_and_things(self) -> Result<(), ZeroVecError>
fn check_indices_and_things(self) -> Result<(), ZeroVecError>
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 check_indices_and_things
Sourcepub fn iter(self) -> impl Iterator<Item = &'a T>
pub fn iter(self) -> impl Iterator<Item = &'a T>
Create an iterator over the Ts contained in VarZeroVecComponents
pub fn to_vec(self) -> Vec<Box<T>>
fn indices_slice(&self) -> &'a [F::RawBytes]
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.
pub fn binary_search_in_range_by( &self, predicate: impl FnMut(&T) -> Ordering, range: Range<usize>, ) -> Option<Result<usize, usize>>
Sourcefn binary_search_impl(
&self,
predicate: impl FnMut(&T) -> Ordering,
indices_slice: &[F::RawBytes],
) -> Result<usize, usize>
fn binary_search_impl( &self, predicate: impl FnMut(&T) -> Ordering, indices_slice: &[F::RawBytes], ) -> Result<usize, usize>
Binary searches a sorted VarZeroVecComponents<T> with the given predicate. For more information, see
the primitive function binary_search.