use std::fmt::Debug;
#[derive(Debug, Clone, PartialEq)]
pub enum Either<A, B>
where A: Debug + Clone + PartialEq,
B: Debug + Clone + PartialEq {
First(A),
Second(B)
}
impl <A, B> Either<A, B>
where A: Debug + Clone + PartialEq,
B: Debug + Clone + PartialEq {
pub fn is_first(&self) -> bool {
match self {
Either::First(_) => true,
Either::Second(_) => false
}
}
pub fn is_second(&self) -> bool {
match self {
Either::First(_) => false,
Either::Second(_) => true
}
}
pub fn first(&self) -> Option<&A> {
match self {
Either::First(a) => Some(a),
Either::Second(_) => None
}
}
pub fn second(&self) -> Option<&B> {
match self {
Either::First(_) => None,
Either::Second(b) => Some(b)
}
}
}