pub struct Coproduct<T: IndexedDrop>(_);
Expand description

Can hold any type. You should use CopyableCoproduct if your types are copyable.

Implementations

Create a new coproduct that holds the given value.

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()
   }
}

Convert a coproduct into another with more variants.

Split a coproduct into two disjoint sets. Returns the active one.

Try to take the first variant out. On failure, return the remaining variants.

From falsehood, anything follows.

Given a coproduct that cannot contain anything, just call this method.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Extract a subset of the possible types in a coproduct (or get the remaining possibilities)

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.