2020-05-16 19:49:29 +00:00
|
|
|
#[derive(
|
|
|
|
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
|
|
|
|
)]
|
2020-05-14 03:54:50 +00:00
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum Either<L, R> {
|
|
|
|
Left(L),
|
|
|
|
Right(R),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<L, R> Either<L, R> {
|
|
|
|
pub fn left(self) -> Option<L> {
|
|
|
|
if let Either::Left(l) = self {
|
|
|
|
Some(l)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn right(self) -> Option<R> {
|
|
|
|
if let Either::Right(r) = self {
|
|
|
|
Some(r)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_ref(&self) -> Either<&L, &R> {
|
|
|
|
match self {
|
|
|
|
Either::Left(ref l) => Either::Left(l),
|
|
|
|
Either::Right(ref r) => Either::Right(r),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|