Skip to content

Commit 1ee058b

Browse files
committed
Moved into the impl
1 parent ad1a7f0 commit 1ee058b

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/either_or_both.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ impl<A, B> EitherOrBoth<A, B> {
163163
Right(b) | Both(_, b) => f(b),
164164
}
165165
}
166+
167+
/// Returns a tuple consisting of the `l` and `r` in `Both(l, r)`, if present.
168+
/// Otherwise, returns the wrapped value for the present element, and the [`default`](Default::default)
169+
/// for the other.
170+
pub fn or_default(self) -> (A, B)
171+
where
172+
A: Default,
173+
B: Default,
174+
{
175+
match self {
176+
EitherOrBoth::Left(l) => (l, B::default()),
177+
EitherOrBoth::Right(r) => (A::default(), r),
178+
EitherOrBoth::Both(l, r) => (l, r),
179+
}
180+
}
166181
}
167182

168183
impl<T> EitherOrBoth<T, T> {
@@ -188,16 +203,3 @@ impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B> {
188203
}
189204
}
190205
}
191-
192-
impl<A: Default, B: Default> EitherOrBoth<A,B> {
193-
/// Returns a tuple consisting of the `l` and `r` in `Both(l, r)`, if present.
194-
/// Otherwise, returns the wrapped value for the present element, and the [`default`](Default::default)
195-
/// for the other.
196-
pub fn or_default(self) -> (A, B) {
197-
match self {
198-
EitherOrBoth::Left(l) => (l, B::default()),
199-
EitherOrBoth::Right(r) => (A::default(), r),
200-
EitherOrBoth::Both(l, r) => (l, r),
201-
}
202-
}
203-
}

0 commit comments

Comments
 (0)