Skip to main content

Discriminant

Struct Discriminant 

Source
pub struct Discriminant<CVar = Vec<u8>, COff = Vec<u64>> {
    pub variant: CVar,
    pub offset: COff,
}
Expand description

Tracks variant discriminants and offsets for enum containers.

Uses two arrays (variant and offset) with three states:

  • Empty: both arrays empty, length is 0.
  • Homogeneous: variant is empty, offset holds [tag, count] where tag = variant_index + 1. All elements share a single variant with identity offsets (element i maps to offset i).
  • Heterogeneous: variant has per-element discriminants (u8), offset has per-element offsets into variant containers (u64).

Fields§

§variant: CVar

Per-element variant discriminants; empty when homogeneous.

§offset: COff

Per-element offsets (heterogeneous), or [tag, count] (homogeneous), or empty.

Implementations§

Source§

impl Discriminant

Source

pub fn push(&mut self, variant: u8, offset: u64)

Push a variant discriminant and the offset into its variant container.

Source

pub fn reserve_for<'a>( &mut self, selves: impl Iterator<Item = Discriminant<&'a [u8], &'a [u64]>> + Clone, )

Pre-allocate for the given borrowed discriminants.

Source§

impl<CVar: Len, COff: Len> Discriminant<CVar, COff>

Source

pub fn is_heterogeneous(&self) -> bool

True if elements have mixed variants, with per-element discriminants and offsets.

Source

pub fn homogeneous(&self) -> Option<u8>
where COff: IndexAs<u64>,

Returns Some(variant) if all elements share a single variant.

Source

pub fn get(&self, index: usize) -> (u8, u64)
where CVar: IndexAs<u8>, COff: IndexAs<u64>,

Returns (variant, offset) for the element at index.

Trait Implementations§

Source§

impl<'a> AsBytes<'a> for Discriminant<&'a [u8], &'a [u64]>

Source§

fn as_bytes(&self) -> impl Iterator<Item = (u64, &'a [u8])>

Presents self as a sequence of byte slices, with their required alignment.
Source§

impl Borrow for Discriminant

Source§

type Ref<'a> = (u8, u64)

For each lifetime, a reference with that lifetime. Read more
Source§

type Borrowed<'a> = Discriminant<&'a [u8], &'a [u64]>

The type of a borrowed container. Read more
Source§

fn borrow<'a>(&'a self) -> Self::Borrowed<'a>

Converts a reference to the type to a borrowed variant. Read more
Source§

fn reborrow<'b, 'a: 'b>(thing: Self::Borrowed<'a>) -> Self::Borrowed<'b>

Reborrows the borrowed type to a shorter lifetime. See Columnar::reborrow for details.
Source§

fn reborrow_ref<'b, 'a: 'b>(thing: Self::Ref<'a>) -> Self::Ref<'b>

Reborrows the borrowed type to a shorter lifetime. See Columnar::reborrow for details.
Source§

impl<CVar: Clear, COff: Clear> Clear for Discriminant<CVar, COff>

Source§

fn clear(&mut self)

Clears self, without changing its capacity.
Source§

impl<CVar: Clone, COff: Clone> Clone for Discriminant<CVar, COff>

Source§

fn clone(&self) -> Discriminant<CVar, COff>

Returns a duplicate 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<CVar: Debug, COff: Debug> Debug for Discriminant<CVar, COff>

Source§

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

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

impl<CVar: Default, COff: Default> Default for Discriminant<CVar, COff>

Source§

fn default() -> Discriminant<CVar, COff>

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

impl<'a> FromBytes<'a> for Discriminant<&'a [u8], &'a [u64]>

Source§

const SLICE_COUNT: usize

The number of byte slices this type consumes when reconstructed.
Source§

fn from_bytes(bytes: &mut impl Iterator<Item = &'a [u8]>) -> Self

Reconstructs self from a sequence of correctly aligned and sized bytes slices. Read more
Source§

fn from_store(store: &DecodedStore<'a>, offset: &mut usize) -> Self

Reconstructs self from a DecodedStore, using direct random access at a given offset. Read more
Source§

fn element_sizes(sizes: &mut Vec<usize>) -> Result<(), String>

Reports the element sizes (in bytes) for each slice this type consumes. Read more
Source§

fn validate(slices: &[(&[u64], u8)]) -> Result<(), String>
where Self: Sized,

Validates that the given slices are compatible with this type. Read more
Source§

impl<'a> Index for Discriminant<&'a [u8], &'a [u64]>

Source§

type Ref = (u8, u64)

The type returned by the get method. Read more
Source§

fn get(&self, index: usize) -> (u8, u64)

Returns the reference type for location index. Read more
Source§

fn last(&self) -> Option<Self::Ref>
where Self: Len,

Source§

fn index_iter(&self) -> IterOwn<&Self>

Converts &self into an iterator. Read more
Source§

fn into_index_iter(self) -> IterOwn<Self>
where Self: Sized,

Converts self into an iterator. Read more
Source§

impl<CVar: Len, COff: Len + IndexAs<u64>> Len for Discriminant<CVar, COff>

Source§

fn len(&self) -> usize

The number of contained elements.
Source§

fn is_empty(&self) -> bool

Whether this contains no elements.
Source§

impl<CVar: PartialEq, COff: PartialEq> PartialEq for Discriminant<CVar, COff>

Source§

fn eq(&self, other: &Discriminant<CVar, COff>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<CVar: Copy, COff: Copy> Copy for Discriminant<CVar, COff>

Source§

impl<CVar, COff> StructuralPartialEq for Discriminant<CVar, COff>

Auto Trait Implementations§

§

impl<CVar, COff> Freeze for Discriminant<CVar, COff>
where CVar: Freeze, COff: Freeze,

§

impl<CVar, COff> RefUnwindSafe for Discriminant<CVar, COff>
where CVar: RefUnwindSafe, COff: RefUnwindSafe,

§

impl<CVar, COff> Send for Discriminant<CVar, COff>
where CVar: Send, COff: Send,

§

impl<CVar, COff> Sync for Discriminant<CVar, COff>
where CVar: Sync, COff: Sync,

§

impl<CVar, COff> Unpin for Discriminant<CVar, COff>
where CVar: Unpin, COff: Unpin,

§

impl<CVar, COff> UnsafeUnpin for Discriminant<CVar, COff>
where CVar: UnsafeUnpin, COff: UnsafeUnpin,

§

impl<CVar, COff> UnwindSafe for Discriminant<CVar, COff>
where CVar: UnwindSafe, COff: UnwindSafe,

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, dest: *mut u8)

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

impl<T> CopyAs<T> for T
where T: Copy,

Source§

fn copy_as(self) -> T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, S> IndexAs<S> for T
where T: Index, <T as Index>::Ref: CopyAs<S>,

Source§

fn index_as(&self, index: usize) -> S

Source§

fn last(&self) -> Option<T>
where Self: Len,

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.