#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Either<L, R> {
Left(L),
Right(R),
}
impl<L, R> Either<L, R> {
#[inline]
pub const fn is_left(&self) -> bool {
matches!(self, Either::Left(_))
}
#[inline]
pub const fn is_right(&self) -> bool {
matches!(self, Either::Right(_))
}
#[inline]
pub fn left(self) -> Option<L> {
match self {
Either::Left(l) => Some(l),
Either::Right(_) => None,
}
}
#[inline]
pub fn right(self) -> Option<R> {
match self {
Either::Left(_) => None,
Either::Right(r) => Some(r),
}
}
#[inline]
pub const fn as_ref(&self) -> Either<&L, &R> {
match self {
Either::Left(l) => Either::Left(l),
Either::Right(r) => Either::Right(r),
}
}
#[inline]
pub fn as_mut(&mut self) -> Either<&mut L, &mut R> {
match self {
Either::Left(l) => Either::Left(l),
Either::Right(r) => Either::Right(r),
}
}
}