@@ -163,6 +163,21 @@ impl<A, B> EitherOrBoth<A, B> {
163
163
Right ( b) | Both ( _, b) => f ( b) ,
164
164
}
165
165
}
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
+ }
166
181
}
167
182
168
183
impl < T > EitherOrBoth < T , T > {
@@ -188,16 +203,3 @@ impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B> {
188
203
}
189
204
}
190
205
}
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