Either

Enum Either 

Source
pub enum Either<Head, Tail> {
    Left(Head),
    Right(Tail),
}
Expand description

The Either type, a.k.a. σ, is used to represent an anonymous sum type.

Similar to Cons, Either is used to form a sum type by combining a chain of Either types, and terminated with a Void type. But unlike product types, a sum type has values that belong to one of the variants in the list.

Either is also shown as σ, together with Void shown as θ, to improve the readability of compiler error messages. Through the shortened name, a sum type would take slightly less space, making it more likely to fit on a single line for the user to read what the type is.

Either is most often used through the Sum! macro, which accepts a list of types and turns them into a chain of Either types.

§Example

Given the following sum type definition:

type MyUnion = Sum![u32, String, bool];

The following type would be generated:

type MyUnion = Either<u32, Either<String, Either<bool, Void>>>;

which would be shown with the shortened representation as:

type MyUnion = σ<u32, σ<String, σ<bool, θ>>>;

Variants§

§

Left(Head)

§

Right(Tail)

Trait Implementations§

Source§

impl<Head, Tail> Clone for σ<Head, Tail>
where Head: Clone, Tail: Clone,

Source§

fn clone(&self) -> σ<Head, Tail>

Returns a duplicate 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<Head, Tail> Debug for σ<Head, Tail>
where Head: Debug, Tail: Debug,

Source§

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

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

impl<Source, Target, Tag, Value, RestFields, Remainder> FieldsExtractor<Source, Target> for σ<ω<Tag, Value>, RestFields>
where Source: ExtractField<Tag, Value = Value>, Target: FromVariant<Tag, Value = Value>, RestFields: FieldsExtractor<<Source as ExtractField<Tag>>::Remainder, Target, Remainder = Remainder>,

Source§

type Remainder = Remainder

Source§

fn extract_from(source: Source) -> Result<Target, Remainder>

Source§

impl<Mapper, Current, Rest> MapFields<Mapper> for σ<Current, Rest>
where Mapper: MapType, Rest: MapFields<Mapper>,

Source§

type Mapped = σ<<Mapper as MapType>::Map<Current>, <Rest as MapFields<Mapper>>::Mapped>

Source§

impl<Head, Tail> PartialEq for σ<Head, Tail>
where Head: PartialEq, Tail: PartialEq,

Source§

fn eq(&self, other: &σ<Head, Tail>) -> 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<Head, Tail> Eq for σ<Head, Tail>
where Head: Eq, Tail: Eq,

Source§

impl<Head, Tail> StructuralPartialEq for σ<Head, Tail>

Auto Trait Implementations§

§

impl<Head, Tail> Freeze for σ<Head, Tail>
where Head: Freeze, Tail: Freeze,

§

impl<Head, Tail> RefUnwindSafe for σ<Head, Tail>
where Head: RefUnwindSafe, Tail: RefUnwindSafe,

§

impl<Head, Tail> Send for σ<Head, Tail>
where Head: Send, Tail: Send,

§

impl<Head, Tail> Sync for σ<Head, Tail>
where Head: Sync, Tail: Sync,

§

impl<Head, Tail> Unpin for σ<Head, Tail>
where Head: Unpin, Tail: Unpin,

§

impl<Head, Tail> UnwindSafe for σ<Head, Tail>
where Head: UnwindSafe, Tail: 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<Builder, Source, Output> CanBuildFrom<Source> for Builder
where Source: HasFields + IntoBuilder, <Source as HasFields>::Fields: FieldsBuilder<<Source as IntoBuilder>::Builder, Builder, Output = Output>,

Source§

type Output = Output

Source§

fn build_from(self, source: Source) -> Output

Source§

impl<Source, Target, Remainder> CanDowncastFields<Target> for Source
where Target: HasFields, <Target as HasFields>::Fields: FieldsExtractor<Source, Target, Remainder = Remainder>,

Source§

type Remainder = Remainder

Source§

fn downcast_fields( self, _tag: PhantomData<Target>, ) -> Result<Target, <Source as CanDowncastFields<Target>>::Remainder>

Source§

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<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.