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::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> VarZeroVecComponents<'a, T, F>

source

pub fn new() -> Self

source§

impl<'a, T: VarULE + ?Sized, F: VarZeroVecFormat> VarZeroVecComponents<'a, T, F>

source

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 array indices of indices
  • indices[i]..indices[i+1] must index into a valid section of things, such that it parses to a T::VarULE
  • indices[len - 1]..things.len() must index into a valid section of things, such that it parses to a T::VarULE
source

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()

source

pub fn len(self) -> usize

Get the number of elements in this vector

source

pub fn is_empty(self) -> bool

Returns true if the vector contains no elements.

source

pub fn get(self, idx: usize) -> Option<&'a T>

Get the idx’th element out of this slice. Returns None if out of bounds.

source

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())
source

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())
source

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())
source

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 of things, such that it parses to a T::VarULE
  • indices[len - 1]..things.len() must index into a valid section of things, such that it parses to a T::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

source

pub fn iter(self) -> impl Iterator<Item = &'a T>

Create an iterator over the Ts contained in VarZeroVecComponents

source

pub fn to_vec(self) -> Vec<Box<T>>

source

fn indices_slice(&self) -> &'a [F::RawBytes]

source

pub(crate) fn dump(&self) -> String

source§

impl<'a, T, F> VarZeroVecComponents<'a, T, F>
where T: VarULE + ?Sized + Ord, F: VarZeroVecFormat,

Binary searches a sorted VarZeroVecComponents<T> for the given element. For more information, see the primitive function binary_search.

source

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>
where T: VarULE + ?Sized, F: VarZeroVecFormat,

source

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.

source

pub fn binary_search_in_range_by( &self, predicate: impl FnMut(&T) -> Ordering, range: Range<usize>, ) -> Option<Result<usize, usize>>

source

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>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, T: Debug + ?Sized, F: Debug> Debug for VarZeroVecComponents<'a, T, F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, T: VarULE + ?Sized, F> Default for VarZeroVecComponents<'a, T, F>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

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>
where F: Send, T: Sync + ?Sized,

§

impl<'a, T, F> Sync for VarZeroVecComponents<'a, T, F>
where F: Sync, T: Sync + ?Sized,

§

impl<'a, T, F> Unpin for VarZeroVecComponents<'a, T, F>
where F: Unpin, T: ?Sized,

§

impl<'a, T, F> UnwindSafe for VarZeroVecComponents<'a, T, F>
where F: UnwindSafe, T: RefUnwindSafe + ?Sized,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,