yoke::either

Enum EitherCart

Source
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 std::rc::Rc;
use yoke::either::EitherCart;
use yoke::Yoke;

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§

Source§

impl<C0: Clone, C1: Clone> Clone for EitherCart<C0, C1>

Source§

fn clone(&self) -> EitherCart<C0, C1>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C0: Debug, C1: Debug> Debug for EitherCart<C0, C1>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C0, C1, T> Deref for EitherCart<C0, C1>
where C0: Deref<Target = T>, C1: Deref<Target = T>,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<C0: PartialEq, C1: PartialEq> PartialEq for EitherCart<C0, C1>

Source§

fn eq(&self, other: &EitherCart<C0, C1>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<C0, C1> CloneableCart for EitherCart<C0, C1>

Source§

impl<C0: Eq, C1: Eq> Eq for EitherCart<C0, C1>

Source§

impl<C0, C1, T> StableDeref for EitherCart<C0, C1>
where C0: StableDeref + Deref<Target = T>, C1: StableDeref + Deref<Target = T>,

Source§

impl<C0, C1> StructuralPartialEq for EitherCart<C0, C1>

Auto Trait Implementations§

§

impl<C0, C1> Freeze for EitherCart<C0, C1>
where C0: Freeze, C1: Freeze,

§

impl<C0, C1> RefUnwindSafe for EitherCart<C0, C1>

§

impl<C0, C1> Send for EitherCart<C0, C1>
where C0: Send, C1: Send,

§

impl<C0, C1> Sync for EitherCart<C0, C1>
where C0: Sync, C1: Sync,

§

impl<C0, C1> Unpin for EitherCart<C0, C1>
where C0: Unpin, C1: Unpin,

§

impl<C0, C1> UnwindSafe for EitherCart<C0, C1>
where C0: UnwindSafe, C1: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,