[−][src]Struct ptr_union::Union4
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.
Methods
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Union4<A, B, C, D>
[src]
pub fn is_a(&self) -> bool
[src]
Check if the union is this variant.
pub fn into_a(self) -> Result<A, Self>
[src]
Extract this variant from the union.
Returns the union on error.
pub fn with_a<R>(&self, f: impl FnOnce(&A) -> R) -> Option<R>
[src]
Run a closure with this variant.
pub fn a(&self) -> Option<&A::Target> where
A: Deref,
[src]
A: Deref,
Get a reference to this variant's target.
pub fn clone_a(&self) -> Option<A> where
A: Clone,
[src]
A: Clone,
Clone this variant out of the union.
pub fn copy_a(&self) -> Option<A> where
A: Copy,
[src]
A: Copy,
Copy this variant out of the union.
pub fn is_b(&self) -> bool
[src]
Check if the union is this variant.
pub fn into_b(self) -> Result<B, Self>
[src]
Extract this variant from the union.
Returns the union on error.
pub fn with_b<R>(&self, f: impl FnOnce(&B) -> R) -> Option<R>
[src]
Run a closure with this variant.
pub fn b(&self) -> Option<&B::Target> where
B: Deref,
[src]
B: Deref,
Get a reference to this variant's target.
pub fn clone_b(&self) -> Option<B> where
B: Clone,
[src]
B: Clone,
Clone this variant out of the union.
pub fn copy_b(&self) -> Option<B> where
B: Copy,
[src]
B: Copy,
Copy this variant out of the union.
pub fn is_c(&self) -> bool
[src]
Check if the union is this variant.
pub fn into_c(self) -> Result<C, Self>
[src]
Extract this variant from the union.
Returns the union on error.
pub fn with_c<R>(&self, f: impl FnOnce(&C) -> R) -> Option<R>
[src]
Run a closure with this variant.
pub fn c(&self) -> Option<&C::Target> where
C: Deref,
[src]
C: Deref,
Get a reference to this variant's target.
pub fn clone_c(&self) -> Option<C> where
C: Clone,
[src]
C: Clone,
Clone this variant out of the union.
pub fn copy_c(&self) -> Option<C> where
C: Copy,
[src]
C: Copy,
Copy this variant out of the union.
pub fn is_d(&self) -> bool
[src]
Check if the union is this variant.
pub fn into_d(self) -> Result<D, Self>
[src]
Extract this variant from the union.
Returns the union on error.
pub fn with_d<R>(&self, f: impl FnOnce(&D) -> R) -> Option<R>
[src]
Run a closure with this variant.
pub fn d(&self) -> Option<&D::Target> where
D: Deref,
[src]
D: Deref,
Get a reference to this variant's target.
pub fn clone_d(&self) -> Option<D> where
D: Clone,
[src]
D: Clone,
Clone this variant out of the union.
pub fn copy_d(&self) -> Option<D> where
D: Copy,
[src]
D: Copy,
Copy this variant out of the union.
pub fn ptr_eq(&self, other: &Self) -> bool
[src]
Check if two unions are the same variant and point to the same value (not that the values compare as equal).
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,
[src]
&'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.
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,
[src]
&'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.
pub fn unpack(self) -> Enum4<A, B, C, D>
[src]
Unpack this union into an enum.
Trait Implementations
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,
[src]
A: Clone,
B: Clone,
C: Clone,
D: Clone,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
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,
[src]
A: Debug,
B: Debug,
C: Debug,
D: Debug,
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> Drop for Union4<A, B, C, D>
[src]
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,
[src]
A: Eq,
B: Eq,
C: Eq,
D: Eq,
impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> ErasablePtr for Union4<A, B, C, D>
[src]
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,
[src]
A: Hash,
B: Hash,
C: Hash,
D: Hash,
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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,
[src]
A: PartialEq,
B: PartialEq,
C: PartialEq,
D: PartialEq,
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,
[src]
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,
[src]
A: Sync,
B: Sync,
C: Sync,
D: Sync,
Auto Trait Implementations
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> Erasable for T
[src]
unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>
[src]
const ACK_1_1_0: bool
[src]
fn erase(this: NonNull<Self>) -> NonNull<Erased>
[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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
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>,