#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[serde(untagged)] pub enum Either { Left(L), Right(R), } impl Either { pub fn left(self) -> Option { if let Either::Left(l) = self { Some(l) } else { None } } pub fn right(self) -> Option { 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), } } pub fn as_mut(&mut self) -> Either<&mut L, &mut R> { match self { Either::Left(ref mut l) => Either::Left(l), Either::Right(ref mut r) => Either::Right(r), } } }