Struct zerovec::ule::MultiFieldsULE

source ·
pub struct MultiFieldsULE(/* private fields */);
Expand description

This type is used by the custom derive to represent multiple VarULE fields packed into a single end-of-struct field. It is not recommended to use this type directly.

Logically, consider it to be (V1, V2, V3, ..) where V1 etc are potentially different VarULE types.

Internally, it is represented by a VarZeroSlice.

Implementations§

source§

impl MultiFieldsULE

source

pub fn compute_encoded_len_for(lengths: &[usize]) -> usize

Compute the amount of bytes needed to support elements with lengths lengths

source

pub fn new_from_lengths_partially_initialized<'a>( lengths: &[usize], output: &'a mut [u8], ) -> &'a mut Self

Construct a partially initialized MultiFieldsULE backed by a mutable byte buffer

source

pub unsafe fn set_field_at<T: VarULE + ?Sized, A: EncodeAsVarULE<T> + ?Sized>( &mut self, idx: usize, value: &A, )

Given a buffer of size obtained by Self::compute_encoded_len_for(), write element A to index idx

§Safety
  • idx must be in range
  • T must be the appropriate type expected by the custom derive in this usage of this type
source

pub unsafe fn validate_field<T: VarULE + ?Sized>( &self, index: usize, ) -> Result<(), ZeroVecError>

Validate field at index to see if it is a valid T VarULE type

§Safety
  • index must be in range
source

pub unsafe fn get_field<T: VarULE + ?Sized>(&self, index: usize) -> &T

Get field at index as a value of type T

§Safety
  • index must be in range
  • Element at index must have been created with the VarULE type T
source

pub unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &Self

Construct from a byte slice

§Safety
  • byte slice must be a valid VarZeroSlice<u8>

Trait Implementations§

source§

impl Debug for MultiFieldsULE

source§

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

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

impl PartialEq for MultiFieldsULE

source§

fn eq(&self, other: &MultiFieldsULE) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl VarULE for MultiFieldsULE

source§

fn validate_byte_slice(slice: &[u8]) -> Result<(), ZeroVecError>

Note: MultiFieldsULE is usually used in cases where one should be calling .validate_field() directly for each field, rather than using the regular VarULE impl.

This impl exists so that EncodeAsVarULE can work.

source§

unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &Self

Takes a byte slice, &[u8], and return it as &Self with the same lifetime, assuming that this byte slice has previously been run through Self::parse_byte_slice() with success. Read more
source§

fn parse_byte_slice(bytes: &[u8]) -> Result<&Self, ZeroVecError>

Parses a byte slice, &[u8], and return it as &Self with the same lifetime. Read more
source§

fn as_byte_slice(&self) -> &[u8]

Given &Self, returns a &[u8] with the same lifetime. Read more
source§

fn to_boxed(&self) -> Box<Self>

Allocate on the heap as a Box<T>
source§

impl Eq for MultiFieldsULE

source§

impl StructuralPartialEq for MultiFieldsULE

Auto Trait Implementations§

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

source§

fn encode_var_ule_as_slices<R>(&self, cb: impl FnOnce(&[&[u8]]) -> R) -> R

Calls cb with a piecewise list of byte slices that when concatenated produce the memory pattern of the corresponding instance of T. Read more
source§

fn encode_var_ule_len(&self) -> usize

Return the length, in bytes, of the corresponding VarULE type
source§

fn encode_var_ule_write(&self, dst: &mut [u8])

Write the corresponding VarULE type to the dst buffer. dst should be the size of Self::encode_var_ule_len()