ConstEither

Struct ConstEither 

Source
pub struct ConstEither<L, R, const IS_RIGHT: bool>(/* private fields */);
Expand description

An Either type that is known to hold a left or right value at compile-time. This allows data structures choose an appropriate type based on some compile-time determined policy.

§Example

struct TheOneVec<T, const INLINE: bool, const MIN_CAPACITY: usize> {
    data: ConstEither<Vec<T>, tinyvec::ArrayVec<[T; MIN_CAPACITY]>, INLINE>,
}

impl<T, const MIN_CAPACITY: usize> TheOneVec<T, false, MIN_CAPACITY> {
    fn new() -> Self {
        TheOneVec { data: ConstEither::new(Vec::with_capacity(MIN_CAPACITY)) }
    }
}

impl<T, const MIN_CAPACITY: usize> TheOneVec<T, true, MIN_CAPACITY> {
    fn new() -> Self {
        TheOneVec { data: ConstEither::new(tinyvec::ArrayVec::new()) }
    }
}

struct TheOneString<const INLINE: bool>(TheOneVec<u8, INLINE, 32>);

struct MaybeHeaplessPerson<const INLINE: bool> {
    name: TheOneString<INLINE>,
    age: usize,
    hobbies: TheOneVec<TheOneString<INLINE>, INLINE, 16>,
}

Implementations§

Source§

impl<L, R> ConstEither<L, R, false>

Source

pub fn new(left: L) -> Self

Source

pub fn into_inner(self) -> L

Source

pub fn flip(self) -> ConstEither<R, L, true>

Source§

impl<L, R> ConstEither<L, R, true>

Source

pub fn new(right: R) -> Self

Source

pub fn into_inner(self) -> R

Source

pub fn flip(self) -> ConstEither<R, L, false>

Trait Implementations§

Source§

impl<L, R> AsMut<L> for ConstEither<L, R, false>

Source§

fn as_mut(&mut self) -> &mut L

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<L, R> AsMut<R> for ConstEither<L, R, true>

Source§

fn as_mut(&mut self) -> &mut R

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<L, R> AsRef<L> for ConstEither<L, R, false>

Source§

fn as_ref(&self) -> &L

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<L, R> AsRef<R> for ConstEither<L, R, true>

Source§

fn as_ref(&self) -> &R

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<L, R> Deref for ConstEither<L, R, false>

Source§

type Target = L

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<L, R> Deref for ConstEither<L, R, true>

Source§

type Target = R

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<L, R> DerefMut for ConstEither<L, R, false>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<L, R> DerefMut for ConstEither<L, R, true>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<L, R, const IS_RIGHT: bool> Drop for ConstEither<L, R, IS_RIGHT>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<L, R, const IS_RIGHT: bool> Freeze for ConstEither<L, R, IS_RIGHT>
where L: Freeze, R: Freeze,

§

impl<L, R, const IS_RIGHT: bool> RefUnwindSafe for ConstEither<L, R, IS_RIGHT>

§

impl<L, R, const IS_RIGHT: bool> Send for ConstEither<L, R, IS_RIGHT>
where L: Send, R: Send,

§

impl<L, R, const IS_RIGHT: bool> Sync for ConstEither<L, R, IS_RIGHT>
where L: Sync, R: Sync,

§

impl<L, R, const IS_RIGHT: bool> Unpin for ConstEither<L, R, IS_RIGHT>
where L: Unpin, R: Unpin,

§

impl<L, R, const IS_RIGHT: bool> UnwindSafe for ConstEither<L, R, IS_RIGHT>
where L: UnwindSafe, R: 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> 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, 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.