Struct zerovec::varzerovec::components::VarZeroVecComponents
source · 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: u32
The number of elements
indices: &'a [u8]
The list of indices into the things
slice
things: &'a [u8]
The contiguous list of T::VarULE
s
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 + 4
bytes total, to form the arrayindices
of indices indices[i]..indices[i+1]
must index into a valid section ofthings
, such that it parses to aT::VarULE
indices[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:
idx
must 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:
idx
must 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:
idx
must 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::VarULE
indices[len - 1]..things.len()
must index into a valid section ofthings
, such that it parses to aT::VarULE
indices
is 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
.
Trait Implementations§
source§impl<'a, T: ?Sized, F> Clone for VarZeroVecComponents<'a, T, F>
impl<'a, T: ?Sized, F> Clone for VarZeroVecComponents<'a, T, F>
impl<'a, T: ?Sized, F> Copy for VarZeroVecComponents<'a, T, F>
Auto Trait Implementations§
impl<'a, T, F> Freeze for VarZeroVecComponents<'a, T, F>where
T: ?Sized,
impl<'a, T, F> RefUnwindSafe for VarZeroVecComponents<'a, T, F>
impl<'a, T, F> Send for VarZeroVecComponents<'a, T, F>
impl<'a, T, F> Sync for VarZeroVecComponents<'a, T, F>
impl<'a, T, F> Unpin for VarZeroVecComponents<'a, T, F>
impl<'a, T, F> UnwindSafe for VarZeroVecComponents<'a, T, F>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)