[−][src]Struct ptr_union::Union2
A pointer union of two pointer types.
This is a tagged union of two pointer types such as Box<T>
, Arc<T>
, or &T
that is only as
big as a 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
(#[repr(align(2))]
).
This is enforced through the use of UnionBuilder
.
Methods
impl<A: ErasablePtr, B: ErasablePtr> Union2<A, B>
[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 ptr_eq(&self, other: &Self) -> bool
[src]
Check if two Union
s are the same variant
and point to the same value
(not that the values compare as equal).
pub fn as_deref<'a>(
&'a self,
proof: UnionBuilder<Union2<&'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,
[src]
&'a self,
proof: UnionBuilder<Union2<&'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.
impl<A: ErasablePtr, B: ErasablePtr> Union2<A, B>
[src]
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,
[src]
&'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 by dereferencing must align to at least u16
(2 bytes).
pub fn unpack(self) -> Enum2<A, B>
[src]
Unpack this union into an enum.
Trait Implementations
impl<A: ErasablePtr, B: ErasablePtr> Clone for Union2<A, B> where
A: Clone,
B: Clone,
[src]
A: Clone,
B: Clone,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<A: ErasablePtr, B: ErasablePtr> Copy for Union2<A, B> where
A: Copy,
B: Copy,
[src]
A: Copy,
B: Copy,
impl<A: ErasablePtr, B: ErasablePtr> Debug for Union2<A, B> where
A: Debug,
B: Debug,
[src]
A: Debug,
B: Debug,
impl<A: ErasablePtr, B: ErasablePtr> Eq for Union2<A, B> where
A: Eq,
B: Eq,
[src]
A: Eq,
B: Eq,
impl<A: ErasablePtr, B: ErasablePtr> Hash for Union2<A, B> where
A: Hash,
B: Hash,
[src]
A: Hash,
B: 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> PartialEq<Union2<A, B>> for Union2<A, B> where
A: PartialEq,
B: PartialEq,
[src]
A: PartialEq,
B: PartialEq,
Auto Trait Implementations
impl<A, B> !Send for Union2<A, B>
impl<A, B> !Sync for Union2<A, B>
impl<A, B> Unpin for Union2<A, B> where
A: Unpin,
B: Unpin,
A: Unpin,
B: Unpin,
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>,