Struct UnsizedEnum

Source
#[repr(C)]
pub struct UnsizedEnum<B, V0: ?Sized, V1> { /* private fields */ }
Expand description

An unsized enum with two variants

As this is a DST, this enum can only be created on the heap. So for convenience, it allows a common base structure to be included in the header before the enum variants. Also, since a lot of space will generally be wasted by the discriminant due to alignment and packing (even if it is only a u8), a whole usize is used and the higher bits in the discriminant are made available to the caller for storage.

The type parameters are: the common base type, the first variant (which may be unsized) and the second variant (which must be sized).

Implementations§

Source§

impl<B, V0, V1> UnsizedEnum<B, V0, V1>

Source

pub fn new_v0(base: B, val: V0) -> Box<Self>

Create a new instance of the V0 type

Source

pub fn new_v1(base: B, val: V1) -> Box<Self>

Create a new instance of the V1 type

Source§

impl<B, V0: ?Sized, V1> UnsizedEnum<B, V0, V1>

Source

pub fn base(&mut self) -> &mut B

Return a mutable reference to the common base structure B

Source

pub fn set_spare(&mut self, spare: usize)

Set a value in the spare bits above the discriminant. Bit 0 of this value will not be stored.

Source

pub fn get_spare(&self) -> usize

Gets the discriminant value including any value stored in the spare bits above it. So bit 0 will be the disriminant (0 for V0, 1 for V1), and the remaining bits will be whatever value was saved by the most recent call to set_spare, or 0 initially.

Source

pub fn set_v0(&mut self, v0: &Move<V0>)

Change the value stored in the enum to the provided V0 value, dropping the previous value (of whichever variant).

Source

pub fn set_v1(&mut self, v1: V1)

Change the value stored in the enum to the provided V1 value, dropping the previous value (of whichever variant)

Source

pub fn get_mut(&mut self) -> EnumRef<'_, V0, V1>

Get a reference to the value. Since there are two possible variants, an enum is returned that provides either one reference or the other.

Trait Implementations§

Source§

impl<B, V0: ?Sized, V1> Drop for UnsizedEnum<B, V0, V1>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<B, V0, V1> Freeze for UnsizedEnum<B, V0, V1>
where B: Freeze, V0: Freeze + ?Sized,

§

impl<B, V0, V1> RefUnwindSafe for UnsizedEnum<B, V0, V1>

§

impl<B, V0, V1> Send for UnsizedEnum<B, V0, V1>
where B: Send, V1: Send, V0: Send + ?Sized,

§

impl<B, V0, V1> Sync for UnsizedEnum<B, V0, V1>
where B: Sync, V1: Sync, V0: Sync + ?Sized,

§

impl<B, V0, V1> Unpin for UnsizedEnum<B, V0, V1>
where B: Unpin, V1: Unpin, V0: Unpin + ?Sized,

§

impl<B, V0, V1> UnwindSafe for UnsizedEnum<B, V0, V1>
where B: UnwindSafe, V1: UnwindSafe, V0: UnwindSafe + ?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> 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, 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.