Union NichedOptionULE

union NichedOptionULE<U: NicheBytes<N> + ULE, N: usize> { ... }

ULE type for [NichedOption<U,N>] where U implements NicheBytes. The invalid bit pattern is used as the niche.

This uses 1 byte less than [crate::ule::OptionULE<U>] to represent [NichedOption<U,N>].

Example

use core::num::NonZeroI8;
use zerovec::ule::NichedOption;
use zerovec::ZeroVec;

let bytes = &[0x00, 0x01, 0x02, 0x00];
let zv_no: ZeroVec<NichedOption<NonZeroI8, 1>> =
    ZeroVec::parse_bytes(bytes).expect("Unable to parse as NichedOption.");

assert_eq!(zv_no.get(0).map(|e| e.0), Some(None));
assert_eq!(zv_no.get(1).map(|e| e.0), Some(NonZeroI8::new(1)));
assert_eq!(zv_no.get(2).map(|e| e.0), Some(NonZeroI8::new(2)));
assert_eq!(zv_no.get(3).map(|e| e.0), Some(None));

Implementations

impl<U: NicheBytes<N> + ULE, N: usize> NichedOptionULE<U, N>

fn new(opt: Option<U>) -> Self

New NichedOptionULE<U, N> from Option<U>

fn get(self: Self) -> Option<U>

Convert to an Option<U>

fn as_ref(self: &Self) -> Option<&U>

Borrows as an Option<&U>.

impl<T> Any for NichedOptionULE<U, N>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for NichedOptionULE<U, N>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for NichedOptionULE<U, N>

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

impl<T> CloneToUninit for NichedOptionULE<U, N>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> ErasedDestructor for NichedOptionULE<U, N>

impl<T> From for NichedOptionULE<U, N>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for NichedOptionULE<U, N>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for NichedOptionULE<U, N>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for NichedOptionULE<U, N>

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

impl<T, U> TryInto for NichedOptionULE<U, N>

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

impl<U, N: usize> Freeze for NichedOptionULE<U, N>

impl<U, N: usize> RefUnwindSafe for NichedOptionULE<U, N>

impl<U, N: usize> Send for NichedOptionULE<U, N>

impl<U, N: usize> Sync for NichedOptionULE<U, N>

impl<U, N: usize> Unpin for NichedOptionULE<U, N>

impl<U, N: usize> UnsafeUnpin for NichedOptionULE<U, N>

impl<U, N: usize> UnwindSafe for NichedOptionULE<U, N>

impl<U: NicheBytes<N> + ULE + Eq, N: usize> Eq for NichedOptionULE<U, N>

impl<U: NicheBytes<N> + ULE + PartialEq, N: usize> PartialEq for NichedOptionULE<U, N>

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

impl<U: NicheBytes<N> + ULE + core::fmt::Debug, N: usize> Debug for NichedOptionULE<U, N>

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

impl<U: NicheBytes<N> + ULE, N: usize> Clone for NichedOptionULE<U, N>

fn clone(self: &Self) -> Self

impl<U: NicheBytes<N> + ULE, N: usize> Copy for NichedOptionULE<U, N>

impl<U: NicheBytes<N> + ULE, N: usize> ULE for NichedOptionULE<U, N>

fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>