[][src]Struct ptr_union::Union2

pub struct Union2<A: ErasablePtr, B: ErasablePtr> { /* fields omitted */ }

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

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]

Get a reference to this variant's target.

pub fn clone_a(&self) -> Option<A> where
    A: Clone
[src]

Clone this variant out of the union.

pub fn copy_a(&self) -> Option<A> where
    A: Copy
[src]

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]

Get a reference to this variant's target.

pub fn clone_b(&self) -> Option<B> where
    B: Clone
[src]

Clone this variant out of the union.

pub fn copy_b(&self) -> Option<B> where
    B: Copy
[src]

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: 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
[src]

Dereference the current pointer.

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]

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) -> Enum2<A, B>[src]

Unpack this union into an enum.

pub fn as_untagged_ptr(&self) -> ErasedPtr[src]

Get the raw type-erased untagged pointer to the payload.

Trait Implementations

impl<A: ErasablePtr, B: ErasablePtr> Clone for Union2<A, B> where
    A: Clone,
    B: Clone
[src]

impl<A: ErasablePtr, B: ErasablePtr> Debug for Union2<A, B> where
    A: Debug,
    B: Debug
[src]

impl<A: ErasablePtr, B: ErasablePtr> Drop for Union2<A, B>[src]

impl<A: ErasablePtr, B: ErasablePtr> Eq for Union2<A, B> where
    A: Eq,
    B: Eq
[src]

impl<A: ErasablePtr, B: ErasablePtr> ErasablePtr for Union2<A, B>[src]

impl<A: ErasablePtr, B: ErasablePtr> Hash for Union2<A, B> where
    A: Hash,
    B: Hash
[src]

impl<A: ErasablePtr, B: ErasablePtr> PartialEq<Union2<A, B>> for Union2<A, B> where
    A: PartialEq,
    B: PartialEq
[src]

impl<A: ErasablePtr, B: ErasablePtr> Send for Union2<A, B> where
    A: Send,
    B: Send
[src]

impl<A: ErasablePtr, B: ErasablePtr> Sync for Union2<A, B> where
    A: Sync,
    B: Sync
[src]

Auto Trait Implementations

impl<A, B> Unpin for Union2<A, B> where
    A: Unpin,
    B: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erasable for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.