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>
impl<L, R> ConstEither<L, R, false>
pub fn new(left: L) -> Self
pub fn into_inner(self) -> L
pub fn flip(self) -> ConstEither<R, L, true>
Source§impl<L, R> ConstEither<L, R, true>
impl<L, R> ConstEither<L, R, true>
pub fn new(right: R) -> Self
pub fn into_inner(self) -> R
pub fn flip(self) -> ConstEither<R, L, false>
Trait Implementations§
Source§impl<L, R> AsMut<L> for ConstEither<L, R, false>
impl<L, R> AsMut<L> for ConstEither<L, R, false>
Source§impl<L, R> AsMut<R> for ConstEither<L, R, true>
impl<L, R> AsMut<R> for ConstEither<L, R, true>
Source§impl<L, R> AsRef<L> for ConstEither<L, R, false>
impl<L, R> AsRef<L> for ConstEither<L, R, false>
Source§impl<L, R> AsRef<R> for ConstEither<L, R, true>
impl<L, R> AsRef<R> for ConstEither<L, R, true>
Source§impl<L, R> Deref for ConstEither<L, R, false>
impl<L, R> Deref for ConstEither<L, R, false>
Source§impl<L, R> Deref for ConstEither<L, R, true>
impl<L, R> Deref for ConstEither<L, R, true>
Source§impl<L, R> DerefMut for ConstEither<L, R, false>
impl<L, R> DerefMut for ConstEither<L, R, false>
Source§impl<L, R> DerefMut for ConstEither<L, R, true>
impl<L, R> DerefMut for ConstEither<L, R, true>
Auto Trait Implementations§
impl<L, R, const IS_RIGHT: bool> Freeze for ConstEither<L, R, IS_RIGHT>
impl<L, R, const IS_RIGHT: bool> RefUnwindSafe for ConstEither<L, R, IS_RIGHT>where
L: RefUnwindSafe,
R: RefUnwindSafe,
impl<L, R, const IS_RIGHT: bool> Send for ConstEither<L, R, IS_RIGHT>
impl<L, R, const IS_RIGHT: bool> Sync for ConstEither<L, R, IS_RIGHT>
impl<L, R, const IS_RIGHT: bool> Unpin for ConstEither<L, R, IS_RIGHT>
impl<L, R, const IS_RIGHT: bool> UnwindSafe for ConstEither<L, R, IS_RIGHT>where
L: UnwindSafe,
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more