pub struct Coproduct<T: IndexedDrop>(_);
Expand description
Can hold any type. You should use CopyableCoproduct if your types are copyable.
Implementations
sourceimpl<T: IndexedDrop> Coproduct<T>
impl<T: IndexedDrop> Coproduct<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> Coproduct<Union<H, T>>where
Union<H, T>: IndexedDrop,
T: IndexedDrop,
impl<H, T> Coproduct<Union<H, T>>where
Union<H, T>: IndexedDrop,
T: IndexedDrop,
sourceimpl Coproduct<EmptyUnion>
impl Coproduct<EmptyUnion>
Trait Implementations
sourceimpl<I, X, U: IndexedDrop> At<I, X> for Coproduct<U>where
U: UnionAt<I, X>,
U::Pruned: IndexedDrop,
I: Count,
impl<I, X, U: IndexedDrop> At<I, X> for Coproduct<U>where
U: UnionAt<I, X>,
U::Pruned: IndexedDrop,
I: Count,
sourceimpl<T: IndexedClone + IndexedDrop> Clone for Coproduct<T>
impl<T: IndexedClone + IndexedDrop> Clone for Coproduct<T>
sourceimpl<T: IndexedDebug + IndexedDrop> Debug for Coproduct<T>
impl<T: IndexedDebug + IndexedDrop> Debug for Coproduct<T>
sourceimpl<T: IndexedDrop> Drop for Coproduct<T>
impl<T: IndexedDrop> Drop for Coproduct<T>
sourceimpl<T: IndexedDrop, I, U: IndexedDrop> Embed<Coproduct<T>, I> for Coproduct<U>where
LeakingCoproduct<U>: Embed<LeakingCoproduct<T>, I>,
impl<T: IndexedDrop, I, U: IndexedDrop> Embed<Coproduct<T>, I> for Coproduct<U>where
LeakingCoproduct<U>: Embed<LeakingCoproduct<T>, I>,
sourceimpl<T> PartialEq<Coproduct<T>> for Coproduct<T>where
T: IndexedEq + IndexedDrop,
impl<T> PartialEq<Coproduct<T>> for Coproduct<T>where
T: IndexedEq + IndexedDrop,
sourceimpl<T: IndexedDrop, I, U: IndexedDrop, Rem> Split<Coproduct<T>, I> for Coproduct<U>where
LeakingCoproduct<U>: Split<LeakingCoproduct<T>, I, Remainder = LeakingCoproduct<Rem>>,
Rem: IndexedDrop,
impl<T: IndexedDrop, I, U: IndexedDrop, Rem> Split<Coproduct<T>, I> for Coproduct<U>where
LeakingCoproduct<U>: Split<LeakingCoproduct<T>, I, Remainder = LeakingCoproduct<Rem>>,
Rem: IndexedDrop,
Auto Trait Implementations
impl<T> RefUnwindSafe for Coproduct<T>where
T: RefUnwindSafe,
impl<T> Send for Coproduct<T>where
T: Send,
impl<T> Sync for Coproduct<T>where
T: Sync,
impl<T> Unpin for Coproduct<T>where
T: Unpin,
impl<T> UnwindSafe for Coproduct<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