[][src]Struct ptr_union::UnionBuilder

pub struct UnionBuilder<U> { /* fields omitted */ }

A builder for pointer unions that enforces correct alignment.

Currently, because there is no way to generically talk about alignment in the type system, this requires the use of unsafe for the programmer to assert that the types are properly aligned. For that, you get all of the unsafe pointer-wrangling for pointer-sized pointer unions.

In the future, with sufficiently advanced const generics, it might be possible to avoid this.

Methods

impl<A, B> UnionBuilder<Union2<A, B>>[src]

pub const unsafe fn new() -> Self[src]

Assert that creating pointer unions of these two types is safe.

Safety

Both A and B pointer types must be erasable, and their erased form must align to at least u16 (#[repr(align(2))]).

Examples

Sound:

UnionBuilder::<Union2<Box<u16>, &u32>>::new();

Unsound:

UnionBuilder::<Union2<Box<u16>, &u8>>::new();

impl<A, B, C, D> UnionBuilder<Union4<A, B, C, D>>[src]

pub const unsafe fn new() -> Self[src]

Assert that creating pointer unions of these four types is safe.

Safety

The A, B, C, and D pointer types must be erasable, and their erased form must align to at least u32 (#[repr(align(4))]).

Examples

Sound:

UnionBuilder::<Union4<Box<u32>, &u32, Arc<u32>, Arc<u64>>>::new();

Unsound:

UnionBuilder::<Union4<Box<u16>, &u16, Arc<u16>, Arc<u64>>>::new();

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

pub fn a(self, a: A) -> Union2<A, B>[src]

Construct a union at this variant.

pub fn b(self, b: B) -> Union2<A, B>[src]

Construct a union at this variant.

impl<A: ErasablePtr, B: ErasablePtr, C: ErasablePtr, D: ErasablePtr> UnionBuilder<Union4<A, B, C, D>>[src]

pub fn a(self, a: A) -> Union4<A, B, C, D>[src]

Construct a union at this variant.

pub fn b(self, b: B) -> Union4<A, B, C, D>[src]

Construct a union at this variant.

pub fn c(self, c: C) -> Union4<A, B, C, D>[src]

Construct a union at this variant.

pub fn d(self, d: D) -> Union4<A, B, C, D>[src]

Construct a union at this variant.

Trait Implementations

impl<U> Clone for UnionBuilder<U>[src]

impl<U> Copy for UnionBuilder<U>[src]

impl<U> Debug for UnionBuilder<U>[src]

Auto Trait Implementations

impl<U> Send for UnionBuilder<U> where
    U: Send

impl<U> Sync for UnionBuilder<U> where
    U: Sync

impl<U> Unpin for UnionBuilder<U> where
    U: 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.