pub struct Union2<A: ErasablePtr, B: ErasablePtr> { /* private fields */ }
Expand description
A pointer union of two pointer types.
This is a tagged union of two 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 u16
(align(2)
).
This is enforced through the use of Builder2
.
Implementations
sourceimpl<A: ErasablePtr, B: ErasablePtr> Union2<A, B>
impl<A: ErasablePtr, B: ErasablePtr> Union2<A, B>
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 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: Builder2<&'a A::Target, &'a B::Target>
) -> Union2<&'a A::Target, &'a B::Target> where
A: Deref,
B: Deref,
&'a A::Target: ErasablePtr,
&'a B::Target: ErasablePtr,
pub fn as_deref<'a>(
&'a self,
builder: Builder2<&'a A::Target, &'a B::Target>
) -> Union2<&'a A::Target, &'a B::Target> where
A: Deref,
B: Deref,
&'a A::Target: ErasablePtr,
&'a B::Target: ErasablePtr,
Dereference the current pointer.
sourcepub unsafe fn as_deref_unchecked<'a>(
&'a self
) -> Union2<&'a A::Target, &'a B::Target> where
A: Deref,
B: Deref,
&'a A::Target: ErasablePtr,
&'a B::Target: ErasablePtr,
pub unsafe fn as_deref_unchecked<'a>(
&'a self
) -> Union2<&'a A::Target, &'a B::Target> where
A: Deref,
B: Deref,
&'a A::Target: ErasablePtr,
&'a B::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.
Trait Implementations
sourceimpl<A: ErasablePtr, B: ErasablePtr> Clone for Union2<A, B> where
A: Clone,
B: Clone,
impl<A: ErasablePtr, B: ErasablePtr> Clone for Union2<A, B> where
A: Clone,
B: Clone,
sourceimpl<A: ErasablePtr, B: ErasablePtr> Debug for Union2<A, B> where
A: Debug,
B: Debug,
impl<A: ErasablePtr, B: ErasablePtr> Debug for Union2<A, B> where
A: Debug,
B: Debug,
sourceimpl<A: ErasablePtr, B: ErasablePtr> Drop for Union2<A, B>
impl<A: ErasablePtr, B: ErasablePtr> Drop for Union2<A, B>
sourceimpl<A: ErasablePtr, B: ErasablePtr> ErasablePtr for Union2<A, B>
impl<A: ErasablePtr, B: ErasablePtr> ErasablePtr for Union2<A, B>
sourceimpl<A: ErasablePtr, B: ErasablePtr> Hash for Union2<A, B> where
A: Hash,
B: Hash,
impl<A: ErasablePtr, B: ErasablePtr> Hash for Union2<A, B> where
A: Hash,
B: Hash,
sourceimpl<A: ErasablePtr, B: ErasablePtr> PartialEq<Union2<A, B>> for Union2<A, B> where
A: PartialEq,
B: PartialEq,
impl<A: ErasablePtr, B: ErasablePtr> PartialEq<Union2<A, B>> for Union2<A, B> where
A: PartialEq,
B: PartialEq,
impl<A: ErasablePtr, B: ErasablePtr> Eq for Union2<A, B> where
A: Eq,
B: Eq,
impl<A: ErasablePtr, B: ErasablePtr> Send for Union2<A, B> where
A: Send,
B: Send,
impl<A: ErasablePtr, B: ErasablePtr> Sync for Union2<A, B> where
A: Sync,
B: Sync,
Auto Trait Implementations
impl<A, B> RefUnwindSafe for Union2<A, B> where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Unpin for Union2<A, B> where
A: Unpin,
B: Unpin,
impl<A, B> UnwindSafe for Union2<A, B> where
A: UnwindSafe,
B: 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