pub struct ArcUnion<A, B> {
pub(crate) p: NonNull<()>,
pub(crate) phantom_a: PhantomData<A>,
pub(crate) phantom_b: PhantomData<B>,
}Expand description
A tagged union that can represent Arc<A> or Arc<B> while only consuming a
single word. The type is also NonNull, and thus can be stored in an Option
without increasing size.
This is functionally equivalent to
enum ArcUnion<A, B> { First(Arc<A>), Second(Arc<B>) but only takes up
up a single word of stack space.
This could probably be extended to support four types if necessary.
Fields§
§p: NonNull<()>§phantom_a: PhantomData<A>§phantom_b: PhantomData<B>Implementations§
Source§impl<A, B> ArcUnion<A, B>
impl<A, B> ArcUnion<A, B>
pub(crate) unsafe fn new(ptr: *mut ()) -> Self
Sourcepub fn ptr_eq(this: &Self, other: &Self) -> bool
pub fn ptr_eq(this: &Self, other: &Self) -> bool
Returns true if the two values are pointer-equal.
pub fn ptr(&self) -> NonNull<()>
Sourcepub fn borrow(&self) -> ArcUnionBorrow<'_, A, B>
pub fn borrow(&self) -> ArcUnionBorrow<'_, A, B>
Returns an enum representing a borrow of either A or B.
Sourcepub fn from_first(other: Arc<A>) -> Self
pub fn from_first(other: Arc<A>) -> Self
Creates an ArcUnion from an instance of the first type.
Sourcepub fn from_second(other: Arc<B>) -> Self
pub fn from_second(other: Arc<B>) -> Self
Creates an ArcUnion from an instance of the second type.
Trait Implementations§
impl<A: Eq, B: Eq> Eq for ArcUnion<A, B>
impl<A: Sync + Send, B: Send + Sync> Send for ArcUnion<A, B>
impl<A: Sync + Send, B: Send + Sync> Sync for ArcUnion<A, B>
Auto Trait Implementations§
impl<A, B> Freeze for ArcUnion<A, B>
impl<A, B> RefUnwindSafe for ArcUnion<A, B>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Unpin for ArcUnion<A, B>
impl<A, B> UnwindSafe for ArcUnion<A, B>where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more