pub enum EitherCart<C0, C1> {
    A(C0),
    B(C1),
}
Expand description

A cart that can be one type or the other. Enables ergonomic polymorphic carts.

EitherCart enables yokes originating from different data sources and therefore having different cart types to be merged into the same yoke type, but still being able to recover the original cart type if necessary.

All relevant Cart traits are implemented for EitherCart, and carts can be safely wrapped in an EitherCart.

Also see Yoke::erase_box_cart().

Examples

use yoke::Yoke;
use yoke::either::EitherCart;
use std::borrow::Cow;
use std::rc::Rc;

let y1: Yoke<
    &'static str,
    Rc<str>
> = Yoke::attach_to_zero_copy_cart(
    "reference counted hello world".into()
);

let y2: Yoke<
    &'static str,
    &str
> = Yoke::attach_to_zero_copy_cart(
    "borrowed hello world"
);

type CombinedYoke<'a> = Yoke<
    &'static str,
    EitherCart<Rc<str>, &'a str>
>;

// Both yokes can be combined into a single yoke type despite different carts
let y3: CombinedYoke = y1.wrap_cart_in_either_a();
let y4: CombinedYoke = y2.wrap_cart_in_either_b();

assert_eq!(*y3.get(), "reference counted hello world");
assert_eq!(*y4.get(), "borrowed hello world");

// The resulting yoke is cloneable if both cart types implement CloneableCart
let y5 = y4.clone();
assert_eq!(*y5.get(), "borrowed hello world");

Variants

A(C0)

B(C1)

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

The resulting type after dereferencing.

Dereferences the value.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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.