activitystreams-new/src/either.rs
2020-05-16 15:40:41 -05:00

33 lines
694 B
Rust

#[derive(
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
)]
#[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),
}
}
}