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§
source§impl<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 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 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 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 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.