pub enum EitherOrBoth<A, B> {
Both(A, B),
Left(A),
Right(B),
}
impl<A, B> EitherOrBoth<A, B> {
pub fn left(&self) -> Option<&A> {
match self {
Self::Both(a, _) => Some(a),
Self::Left(a) => Some(a),
Self::Right(_) => None,
}
}
pub fn right(&self) -> Option<&B> {
match self {
Self::Both(_, b) => Some(b),
Self::Left(_) => None,
Self::Right(b) => Some(b),
}
}
}
impl<T> EitherOrBoth<T, T> {
pub fn right_or_left(&self) -> &T {
match self {
Self::Left(a) => a,
Self::Right(b) => b,
Self::Both(_a, b) => b,
}
}
}
#[allow(dead_code)]
pub(crate) fn then_some<T>(b: bool, v: T) -> Option<T> {
if b {
Some(v)
} else {
None
}
}