[−][src]Struct unsized_enum::UnsizedEnum
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
impl<B, V0, V1> UnsizedEnum<B, V0, V1>
[src]
pub fn new_v0(base: B, val: V0) -> Box<Self>
[src]
Create a new instance of the V0 type
pub fn new_v1(base: B, val: V1) -> Box<Self>
[src]
Create a new instance of the V1 type
impl<B, V0: ?Sized, V1> UnsizedEnum<B, V0, V1>
[src]
pub fn base(&mut self) -> &mut B
[src]
Return a mutable reference to the common base structure B
pub fn set_spare(&mut self, spare: usize)
[src]
Set a value in the spare bits above the discriminant. Bit 0 of this value will not be stored.
pub fn get_spare(&self) -> usize
[src]
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.
pub fn set_v0(&mut self, v0: &Move<V0>)
[src]
Change the value stored in the enum to the provided V0
value, dropping the previous value (of whichever variant).
pub fn set_v1(&mut self, v1: V1)
[src]
Change the value stored in the enum to the provided V1 value, dropping the previous value (of whichever variant)
pub fn get_mut(&mut self) -> EnumRef<V0, V1>
[src]
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
Auto Trait Implementations
impl<B, V0: ?Sized, V1> RefUnwindSafe for UnsizedEnum<B, V0, V1> where
B: RefUnwindSafe,
V0: RefUnwindSafe,
V1: RefUnwindSafe,
B: RefUnwindSafe,
V0: RefUnwindSafe,
V1: RefUnwindSafe,
impl<B, V0: ?Sized, V1> Send for UnsizedEnum<B, V0, V1> where
B: Send,
V0: Send,
V1: Send,
B: Send,
V0: Send,
V1: Send,
impl<B, V0: ?Sized, V1> Sync for UnsizedEnum<B, V0, V1> where
B: Sync,
V0: Sync,
V1: Sync,
B: Sync,
V0: Sync,
V1: Sync,
impl<B, V0: ?Sized, V1> Unpin for UnsizedEnum<B, V0, V1> where
B: Unpin,
V0: Unpin,
V1: Unpin,
B: Unpin,
V0: Unpin,
V1: Unpin,
impl<B, V0: ?Sized, V1> UnwindSafe for UnsizedEnum<B, V0, V1> where
B: UnwindSafe,
V0: UnwindSafe,
V1: UnwindSafe,
B: UnwindSafe,
V0: UnwindSafe,
V1: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,