Union8

Struct Union8 

Source
pub struct Union8<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr, E: ErasablePtr, F: ErasablePtr = NeverPtr, G: ErasablePtr = NeverPtr, H: ErasablePtr = NeverPtr> { /* private fields */ }
Expand description

A pointer union of eight pointer types.

This is a tagged union of eight pointer types such as Box, Arc, or & that is only as big as a single pointer. This is accomplished by storing the tag in the alignment bits of the pointer.

As such, the pointer must be aligned to at least u64 (align(8)). This is enforced through the use of Builder8.

Pointers beyond the fifth may be ommitted to create smaller unions. The default type, NeverPtr, will be an alias for ! once it is stable. This will not be considered a breaking change.

Implementations§

Source§

impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr, E: ErasablePtr, F: ErasablePtr, G: ErasablePtr, H: ErasablePtr> Union8<A, B, C, D, E, F, G, H>

Source

pub fn new_a(a: A) -> Result<Self, A>

Construct a varaint of this union with a dynamic alignment check.

Source

pub fn is_a(&self) -> bool

Check if the union is this variant.

Source

pub fn into_a(self) -> Result<A, Self>

Extract this variant from the union.

Returns the union on error.

Source

pub fn with_a<R>(&self, f: impl FnOnce(&A) -> R) -> Option<R>

Run a closure with this variant.

Source

pub fn a(&self) -> Option<&A::Target>
where A: Deref,

Get a reference to this variant’s target.

Source

pub fn clone_a(&self) -> Option<A>
where A: Clone,

Clone this variant out of the union.

Source

pub fn copy_a(&self) -> Option<A>
where A: Copy,

Copy this variant out of the union.

Source

pub fn new_b(b: B) -> Result<Self, B>

Construct a varaint of this union with a dynamic alignment check.

Source

pub fn is_b(&self) -> bool

Check if the union is this variant.

Source

pub fn into_b(self) -> Result<B, Self>

Extract this variant from the union.

Returns the union on error.

Source

pub fn with_b<R>(&self, f: impl FnOnce(&B) -> R) -> Option<R>

Run a closure with this variant.

Source

pub fn b(&self) -> Option<&B::Target>
where B: Deref,

Get a reference to this variant’s target.

Source

pub fn clone_b(&self) -> Option<B>
where B: Clone,

Clone this variant out of the union.

Source

pub fn copy_b(&self) -> Option<B>
where B: Copy,

Copy this variant out of the union.

Source

pub fn new_c(c: C) -> Result<Self, C>

Construct a varaint of this union with a dynamic alignment check.

Source

pub fn is_c(&self) -> bool

Check if the union is this variant.

Source

pub fn into_c(self) -> Result<C, Self>

Extract this variant from the union.

Returns the union on error.

Source

pub fn with_c<R>(&self, f: impl FnOnce(&C) -> R) -> Option<R>

Run a closure with this variant.

Source

pub fn c(&self) -> Option<&C::Target>
where C: Deref,

Get a reference to this variant’s target.

Source

pub fn clone_c(&self) -> Option<C>
where C: Clone,

Clone this variant out of the union.

Source

pub fn copy_c(&self) -> Option<C>
where C: Copy,

Copy this variant out of the union.

Source

pub fn new_d(d: D) -> Result<Self, D>

Construct a varaint of this union with a dynamic alignment check.

Source

pub fn is_d(&self) -> bool

Check if the union is this variant.

Source

pub fn into_d(self) -> Result<D, Self>

Extract this variant from the union.

Returns the union on error.

Source

pub fn with_d<R>(&self, f: impl FnOnce(&D) -> R) -> Option<R>

Run a closure with this variant.

Source

pub fn d(&self) -> Option<&D::Target>
where D: Deref,

Get a reference to this variant’s target.

Source

pub fn clone_d(&self) -> Option<D>
where D: Clone,

Clone this variant out of the union.

Source

pub fn copy_d(&self) -> Option<D>
where D: Copy,

Copy this variant out of the union.

Source

pub fn new_e(e: E) -> Result<Self, E>

Construct a varaint of this union with a dynamic alignment check.

Source

pub fn is_e(&self) -> bool

Check if the union is this variant.

Source

pub fn into_e(self) -> Result<E, Self>

Extract this variant from the union.

Returns the union on error.

Source

pub fn with_e<R>(&self, f: impl FnOnce(&E) -> R) -> Option<R>

Run a closure with this variant.

Source

pub fn e(&self) -> Option<&E::Target>
where E: Deref,

Get a reference to this variant’s target.

Source

pub fn clone_e(&self) -> Option<E>
where E: Clone,

Clone this variant out of the union.

Source

pub fn copy_e(&self) -> Option<E>
where E: Copy,

Copy this variant out of the union.

Source

pub fn new_f(f: F) -> Result<Self, F>

Construct a varaint of this union with a dynamic alignment check.

Source

pub fn is_f(&self) -> bool

Check if the union is this variant.

Source

pub fn into_f(self) -> Result<F, Self>

Extract this variant from the union.

Returns the union on error.

Source

pub fn with_f<R>(&self, f: impl FnOnce(&F) -> R) -> Option<R>

Run a closure with this variant.

Source

pub fn f(&self) -> Option<&F::Target>
where F: Deref,

Get a reference to this variant’s target.

Source

pub fn clone_f(&self) -> Option<F>
where F: Clone,

Clone this variant out of the union.

Source

pub fn copy_f(&self) -> Option<F>
where F: Copy,

Copy this variant out of the union.

Source

pub fn new_g(g: G) -> Result<Self, G>

Construct a varaint of this union with a dynamic alignment check.

Source

pub fn is_g(&self) -> bool

Check if the union is this variant.

Source

pub fn into_g(self) -> Result<G, Self>

Extract this variant from the union.

Returns the union on error.

Source

pub fn with_g<R>(&self, f: impl FnOnce(&G) -> R) -> Option<R>

Run a closure with this variant.

Source

pub fn g(&self) -> Option<&G::Target>
where G: Deref,

Get a reference to this variant’s target.

Source

pub fn clone_g(&self) -> Option<G>
where G: Clone,

Clone this variant out of the union.

Source

pub fn copy_g(&self) -> Option<G>
where G: Copy,

Copy this variant out of the union.

Source

pub fn new_h(h: H) -> Result<Self, H>

Construct a varaint of this union with a dynamic alignment check.

Source

pub fn is_h(&self) -> bool

Check if the union is this variant.

Source

pub fn into_h(self) -> Result<H, Self>

Extract this variant from the union.

Returns the union on error.

Source

pub fn with_h<R>(&self, f: impl FnOnce(&H) -> R) -> Option<R>

Run a closure with this variant.

Source

pub fn h(&self) -> Option<&H::Target>
where H: Deref,

Get a reference to this variant’s target.

Source

pub fn clone_h(&self) -> Option<H>
where H: Clone,

Clone this variant out of the union.

Source

pub fn copy_h(&self) -> Option<H>
where H: Copy,

Copy this variant out of the union.

Source

pub fn unpack(self) -> Enum8<A, B, C, D, E, F, G, H>

Unpack this union into an enum.

Source

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

Check if two unions are the same variant and point to the same value (not that the values compare as equal).

Source

pub fn as_deref<'a>( &'a self, builder: Builder8<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target, &'a E::Target, &'a F::Target, &'a G::Target, &'a H::Target>, ) -> Union8<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target, &'a E::Target, &'a F::Target, &'a G::Target, &'a H::Target>
where A: Deref, B: Deref, C: Deref, D: Deref, E: Deref, F: Deref, G: Deref, H: Deref, &'a A::Target: ErasablePtr, &'a B::Target: ErasablePtr, &'a C::Target: ErasablePtr, &'a D::Target: ErasablePtr, &'a E::Target: ErasablePtr, &'a F::Target: ErasablePtr, &'a G::Target: ErasablePtr, &'a H::Target: ErasablePtr,

Dereference the current pointer.

Source

pub unsafe fn as_deref_unchecked<'a>( &'a self, ) -> Union8<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target, &'a E::Target, &'a F::Target, &'a G::Target, &'a H::Target>
where A: Deref, B: Deref, C: Deref, D: Deref, E: Deref, F: Deref, G: Deref, H: Deref, &'a A::Target: ErasablePtr, &'a B::Target: ErasablePtr, &'a C::Target: ErasablePtr, &'a D::Target: ErasablePtr, &'a E::Target: ErasablePtr, &'a F::Target: ErasablePtr, &'a G::Target: ErasablePtr, &'a H::Target: ErasablePtr,

Dereference the current pointer.

§Safety

The reference produced must be properly aligned. Note that only the actually produced reference is restricted, not the result of dereferencing any of the other types in this union.

Source

pub fn as_untagged_ptr(&self) -> ErasedPtr

Get the raw type-erased untagged pointer to the payload.

Source

pub fn try_deref<'a>( &'a self, ) -> Option<Union8<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target, &'a E::Target, &'a F::Target, &'a G::Target, &'a H::Target>>
where A: Deref, B: Deref, C: Deref, D: Deref, E: Deref, F: Deref, G: Deref, H: Deref, &'a A::Target: ErasablePtr, &'a B::Target: ErasablePtr, &'a C::Target: ErasablePtr, &'a D::Target: ErasablePtr, &'a E::Target: ErasablePtr, &'a F::Target: ErasablePtr, &'a G::Target: ErasablePtr, &'a H::Target: ErasablePtr,

Dereference the current pointer.

Performs a dynamic alignment check on the dereferenced pointer.

Trait Implementations§

Source§

impl<A, B, C, D, E, F, G, H> Clone for Union8<A, B, C, D, E, F, G, H>

Source§

fn clone(&self) -> Self

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<A, B, C, D, E, F, G, H> Debug for Union8<A, B, C, D, E, F, G, H>

Source§

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

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

impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr, E: ErasablePtr, F: ErasablePtr, G: ErasablePtr, H: ErasablePtr> Drop for Union8<A, B, C, D, E, F, G, H>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr, E: ErasablePtr, F: ErasablePtr, G: ErasablePtr, H: ErasablePtr> ErasablePtr for Union8<A, B, C, D, E, F, G, H>

Source§

fn erase(this: Self) -> ErasedPtr

Turn this erasable pointer into an erased pointer. Read more
Source§

unsafe fn unerase(this: ErasedPtr) -> Self

Unerase this erased pointer. Read more
Source§

impl<A, B, C, D, E, F, G, H> Hash for Union8<A, B, C, D, E, F, G, H>

Source§

fn hash<Hasher>(&self, state: &mut Hasher)
where Hasher: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<A, B, C, D, E, F, G, H> PartialEq for Union8<A, B, C, D, E, F, G, H>

Source§

fn eq(&self, other: &Self) -> 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<A, B, C, D, E, F, G, H> Eq for Union8<A, B, C, D, E, F, G, H>

Source§

impl<A, B, C, D, E, F, G, H> Send for Union8<A, B, C, D, E, F, G, H>

Source§

impl<A, B, C, D, E, F, G, H> Sync for Union8<A, B, C, D, E, F, G, H>

Auto Trait Implementations§

§

impl<A, B, C, D, E, F, G, H> Freeze for Union8<A, B, C, D, E, F, G, H>

§

impl<A, B, C, D, E, F, G, H> RefUnwindSafe for Union8<A, B, C, D, E, F, G, H>

§

impl<A, B, C, D, E, F, G, H> Unpin for Union8<A, B, C, D, E, F, G, H>
where A: Unpin, B: Unpin, C: Unpin, D: Unpin, E: Unpin, F: Unpin, G: Unpin, H: Unpin,

§

impl<A, B, C, D, E, F, G, H> UnwindSafe for Union8<A, B, C, D, E, F, G, H>

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> Erasable for T

Source§

const ACK_1_1_0: bool = true

Whether this implementor has acknowledged the 1.1.0 update to unerase’s documented implementation requirements. Read more
Source§

unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>

Unerase this erased pointer. Read more
Source§

fn erase(this: NonNull<Self>) -> NonNull<Erased>

Turn this erasable pointer into an erased pointer. 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> 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.