pub struct Union4<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr = NeverPtr> { /* private fields */ }
Expand description
A pointer union of four pointer types.
This is a tagged union of four 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 u32
(align(4)
).
This is enforced through the use of Builder4
.
The fourth pointer type may be omitted to create a three pointer union.
The default type, NeverPtr
, will be an alias for !
once it is stable.
This will not be considered a breaking change.
Implementations
sourceimpl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Union4<A, B, C, D>
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Union4<A, B, C, D>
sourcepub fn new_a(a: A) -> Result<Self, A>
pub fn new_a(a: A) -> Result<Self, A>
Construct a varaint of this union with a dynamic alignment check.
sourcepub fn into_a(self) -> Result<A, Self>
pub fn into_a(self) -> Result<A, Self>
Extract this variant from the union.
Returns the union on error.
sourcepub fn a(&self) -> Option<&A::Target> where
A: Deref,
pub fn a(&self) -> Option<&A::Target> where
A: Deref,
Get a reference to this variant’s target.
sourcepub fn new_b(b: B) -> Result<Self, B>
pub fn new_b(b: B) -> Result<Self, B>
Construct a varaint of this union with a dynamic alignment check.
sourcepub fn into_b(self) -> Result<B, Self>
pub fn into_b(self) -> Result<B, Self>
Extract this variant from the union.
Returns the union on error.
sourcepub fn b(&self) -> Option<&B::Target> where
B: Deref,
pub fn b(&self) -> Option<&B::Target> where
B: Deref,
Get a reference to this variant’s target.
sourcepub fn new_c(c: C) -> Result<Self, C>
pub fn new_c(c: C) -> Result<Self, C>
Construct a varaint of this union with a dynamic alignment check.
sourcepub fn into_c(self) -> Result<C, Self>
pub fn into_c(self) -> Result<C, Self>
Extract this variant from the union.
Returns the union on error.
sourcepub fn c(&self) -> Option<&C::Target> where
C: Deref,
pub fn c(&self) -> Option<&C::Target> where
C: Deref,
Get a reference to this variant’s target.
sourcepub fn new_d(d: D) -> Result<Self, D>
pub fn new_d(d: D) -> Result<Self, D>
Construct a varaint of this union with a dynamic alignment check.
sourcepub fn into_d(self) -> Result<D, Self>
pub fn into_d(self) -> Result<D, Self>
Extract this variant from the union.
Returns the union on error.
sourcepub fn d(&self) -> Option<&D::Target> where
D: Deref,
pub fn d(&self) -> Option<&D::Target> where
D: Deref,
Get a reference to this variant’s target.
sourcepub fn ptr_eq(&self, other: &Self) -> bool
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).
sourcepub fn as_deref<'a>(
&'a self,
builder: Builder4<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target>
) -> Union4<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target> where
A: Deref,
B: Deref,
C: Deref,
D: Deref,
&'a A::Target: ErasablePtr,
&'a B::Target: ErasablePtr,
&'a C::Target: ErasablePtr,
&'a D::Target: ErasablePtr,
pub fn as_deref<'a>(
&'a self,
builder: Builder4<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target>
) -> Union4<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target> where
A: Deref,
B: Deref,
C: Deref,
D: Deref,
&'a A::Target: ErasablePtr,
&'a B::Target: ErasablePtr,
&'a C::Target: ErasablePtr,
&'a D::Target: ErasablePtr,
Dereference the current pointer.
sourcepub unsafe fn as_deref_unchecked<'a>(
&'a self
) -> Union4<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target> where
A: Deref,
B: Deref,
C: Deref,
D: Deref,
&'a A::Target: ErasablePtr,
&'a B::Target: ErasablePtr,
&'a C::Target: ErasablePtr,
&'a D::Target: ErasablePtr,
pub unsafe fn as_deref_unchecked<'a>(
&'a self
) -> Union4<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target> where
A: Deref,
B: Deref,
C: Deref,
D: Deref,
&'a A::Target: ErasablePtr,
&'a B::Target: ErasablePtr,
&'a C::Target: ErasablePtr,
&'a D::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.
sourcepub fn as_untagged_ptr(&self) -> ErasedPtr
pub fn as_untagged_ptr(&self) -> ErasedPtr
Get the raw type-erased untagged pointer to the payload.
sourcepub fn try_deref<'a>(
&'a self
) -> Option<Union4<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target>> where
A: Deref,
B: Deref,
C: Deref,
D: Deref,
&'a A::Target: ErasablePtr,
&'a B::Target: ErasablePtr,
&'a C::Target: ErasablePtr,
&'a D::Target: ErasablePtr,
pub fn try_deref<'a>(
&'a self
) -> Option<Union4<&'a A::Target, &'a B::Target, &'a C::Target, &'a D::Target>> where
A: Deref,
B: Deref,
C: Deref,
D: Deref,
&'a A::Target: ErasablePtr,
&'a B::Target: ErasablePtr,
&'a C::Target: ErasablePtr,
&'a D::Target: ErasablePtr,
Dereference the current pointer.
Performs a dynamic alignment check on the dereferenced pointer.
Trait Implementations
sourceimpl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Clone for Union4<A, B, C, D> where
A: Clone,
B: Clone,
C: Clone,
D: Clone,
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Clone for Union4<A, B, C, D> where
A: Clone,
B: Clone,
C: Clone,
D: Clone,
sourceimpl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Debug for Union4<A, B, C, D> where
A: Debug,
B: Debug,
C: Debug,
D: Debug,
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Debug for Union4<A, B, C, D> where
A: Debug,
B: Debug,
C: Debug,
D: Debug,
sourceimpl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Drop for Union4<A, B, C, D>
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Drop for Union4<A, B, C, D>
sourceimpl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> ErasablePtr for Union4<A, B, C, D>
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> ErasablePtr for Union4<A, B, C, D>
sourceimpl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Hash for Union4<A, B, C, D> where
A: Hash,
B: Hash,
C: Hash,
D: Hash,
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Hash for Union4<A, B, C, D> where
A: Hash,
B: Hash,
C: Hash,
D: Hash,
sourceimpl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> PartialEq<Union4<A, B, C, D>> for Union4<A, B, C, D> where
A: PartialEq,
B: PartialEq,
C: PartialEq,
D: PartialEq,
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> PartialEq<Union4<A, B, C, D>> for Union4<A, B, C, D> where
A: PartialEq,
B: PartialEq,
C: PartialEq,
D: PartialEq,
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Eq for Union4<A, B, C, D> where
A: Eq,
B: Eq,
C: Eq,
D: Eq,
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Send for Union4<A, B, C, D> where
A: Send,
B: Send,
C: Send,
D: Send,
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Sync for Union4<A, B, C, D> where
A: Sync,
B: Sync,
C: Sync,
D: Sync,
Auto Trait Implementations
impl<A, B, C, D> RefUnwindSafe for Union4<A, B, C, D> where
A: RefUnwindSafe,
B: RefUnwindSafe,
C: RefUnwindSafe,
D: RefUnwindSafe,
impl<A, B, C, D> Unpin for Union4<A, B, C, D> where
A: Unpin,
B: Unpin,
C: Unpin,
D: Unpin,
impl<A, B, C, D> UnwindSafe for Union4<A, B, C, D> where
A: UnwindSafe,
B: UnwindSafe,
C: UnwindSafe,
D: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Erasable for T
impl<T> Erasable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more