diff --git a/src/either_or_both.rs b/src/either_or_both.rs index 3598f49f3..982b85189 100644 --- a/src/either_or_both.rs +++ b/src/either_or_both.rs @@ -163,6 +163,21 @@ impl EitherOrBoth { Right(b) | Both(_, b) => f(b), } } + + /// Returns a tuple consisting of the `l` and `r` in `Both(l, r)`, if present. + /// Otherwise, returns the wrapped value for the present element, and the [`default`](Default::default) + /// for the other. + pub fn or_default(self) -> (A, B) + where + A: Default, + B: Default, + { + match self { + EitherOrBoth::Left(l) => (l, B::default()), + EitherOrBoth::Right(r) => (A::default(), r), + EitherOrBoth::Both(l, r) => (l, r), + } + } } impl EitherOrBoth {