Struct coproduct::CopyableCoproduct
source · [−]pub struct CopyableCoproduct<T>(_)
where
T: Copy;
Expand description
A coproduct that can only hold copyable types.
Implementations
sourceimpl<T: Copy> CopyableCoproduct<T>
impl<T: Copy> CopyableCoproduct<T>
sourcepub fn inject<I, X>(x: X) -> Selfwhere
Self: At<I, X>,
pub fn inject<I, X>(x: X) -> Selfwhere
Self: At<I, X>,
Create a new coproduct that holds the given value.
sourcepub fn uninject<I, X>(self) -> Result<X, <Self as At<I, X>>::Pruned>where
Self: At<I, X>,
pub fn uninject<I, X>(self) -> Result<X, <Self as At<I, X>>::Pruned>where
Self: At<I, X>,
If the coproduct contains an X, returns that value. Otherwise, returns the same coproduct, refined to indicate that it cannot contain X.
This method can be used to do exhaustive case analysis on a coproduct:
let animal: Coproduct!(Cat, Dog) = Coproduct::inject(Dog("Sparky"));
let non_cat = match animal.uninject::<_, Cat>() {
Ok(_) => unreachable!(),
Err(non_cat) => non_cat,
};
match non_cat.uninject::<_, Dog>() {
Ok(dog) => assert_eq!(dog, Dog("Sparky")),
Err(non_animal) => {
// There are animals other than cats and dogs? Absurd!
non_animal.ex_falso()
}
}
sourceimpl<H, T> CopyableCoproduct<Union<H, T>>where
Union<H, T>: Copy,
T: Copy,
impl<H, T> CopyableCoproduct<Union<H, T>>where
Union<H, T>: Copy,
T: Copy,
sourcepub fn take_head(self) -> Result<H, CopyableCoproduct<T>>
pub fn take_head(self) -> Result<H, CopyableCoproduct<T>>
Try to take the first variant out. On failure, return the remaining variants.
Trait Implementations
sourceimpl<I, X, U: Copy> At<I, X> for CopyableCoproduct<U>where
U: UnionAt<I, X>,
U::Pruned: Copy,
I: Count,
impl<I, X, U: Copy> At<I, X> for CopyableCoproduct<U>where
U: UnionAt<I, X>,
U::Pruned: Copy,
I: Count,
sourceimpl<T: Clone> Clone for CopyableCoproduct<T>where
T: Copy,
impl<T: Clone> Clone for CopyableCoproduct<T>where
T: Copy,
sourcefn clone(&self) -> CopyableCoproduct<T>
fn clone(&self) -> CopyableCoproduct<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<T: IndexedDebug + Copy> Debug for CopyableCoproduct<T>
impl<T: IndexedDebug + Copy> Debug for CopyableCoproduct<T>
sourceimpl<T: Copy, I, U: Copy> Embed<CopyableCoproduct<T>, I> for CopyableCoproduct<U>where
LeakingCoproduct<U>: Embed<LeakingCoproduct<T>, I>,
impl<T: Copy, I, U: Copy> Embed<CopyableCoproduct<T>, I> for CopyableCoproduct<U>where
LeakingCoproduct<U>: Embed<LeakingCoproduct<T>, I>,
fn embed(self) -> CopyableCoproduct<T>
sourceimpl<T> PartialEq<CopyableCoproduct<T>> for CopyableCoproduct<T>where
T: IndexedEq + Copy,
impl<T> PartialEq<CopyableCoproduct<T>> for CopyableCoproduct<T>where
T: IndexedEq + Copy,
sourceimpl<T: Copy, I, U: Copy, Rem> Split<CopyableCoproduct<T>, I> for CopyableCoproduct<U>where
LeakingCoproduct<U>: Split<LeakingCoproduct<T>, I, Remainder = LeakingCoproduct<Rem>>,
Rem: Copy,
impl<T: Copy, I, U: Copy, Rem> Split<CopyableCoproduct<T>, I> for CopyableCoproduct<U>where
LeakingCoproduct<U>: Split<LeakingCoproduct<T>, I, Remainder = LeakingCoproduct<Rem>>,
Rem: Copy,
type Remainder = CopyableCoproduct<Rem>
sourcefn split(self) -> Result<CopyableCoproduct<T>, CopyableCoproduct<Rem>>
fn split(self) -> Result<CopyableCoproduct<T>, CopyableCoproduct<Rem>>
Extract a subset of the possible types in a coproduct (or get the remaining possibilities)
impl<T: Copy> Copy for CopyableCoproduct<T>where
T: Copy,
Auto Trait Implementations
impl<T> RefUnwindSafe for CopyableCoproduct<T>where
T: RefUnwindSafe,
impl<T> Send for CopyableCoproduct<T>where
T: Send,
impl<T> Sync for CopyableCoproduct<T>where
T: Sync,
impl<T> Unpin for CopyableCoproduct<T>where
T: Unpin,
impl<T> UnwindSafe for CopyableCoproduct<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more