1- use crate :: EitherOrBoth :: * ;
2-
31use either:: Either ;
42
53/// Value that either holds a single A or B, or both.
@@ -28,7 +26,7 @@ impl<A, B> EitherOrBoth<A, B> {
2826 /// Exclusive version of [`has_left`](EitherOrBoth::has_left).
2927 pub fn is_left ( & self ) -> bool {
3028 match * self {
31- Left ( _) => true ,
29+ EitherOrBoth :: Left ( _) => true ,
3230 _ => false ,
3331 }
3432 }
@@ -37,7 +35,7 @@ impl<A, B> EitherOrBoth<A, B> {
3735 /// Exclusive version of [`has_right`](EitherOrBoth::has_right).
3836 pub fn is_right ( & self ) -> bool {
3937 match * self {
40- Right ( _) => true ,
38+ EitherOrBoth :: Right ( _) => true ,
4139 _ => false ,
4240 }
4341 }
@@ -51,51 +49,51 @@ impl<A, B> EitherOrBoth<A, B> {
5149 /// If `Left`, or `Both`, return `Some` with the left value, otherwise, return `None`.
5250 pub fn left ( self ) -> Option < A > {
5351 match self {
54- Left ( left) | Both ( left, _) => Some ( left) ,
55- _ => None ,
52+ EitherOrBoth :: Left ( left) | EitherOrBoth :: Both ( left, _) => Some ( left) ,
53+ EitherOrBoth :: Right ( _ ) => None ,
5654 }
5755 }
5856
5957 /// If `Right`, or `Both`, return `Some` with the right value, otherwise, return `None`.
6058 pub fn right ( self ) -> Option < B > {
6159 match self {
62- Right ( right) | Both ( _, right) => Some ( right) ,
63- _ => None ,
60+ EitherOrBoth :: Right ( right) | EitherOrBoth :: Both ( _, right) => Some ( right) ,
61+ EitherOrBoth :: Left ( _ ) => None ,
6462 }
6563 }
6664
6765 /// If Both, return `Some` tuple containing left and right.
6866 pub fn both ( self ) -> Option < ( A , B ) > {
6967 match self {
70- Both ( a, b) => Some ( ( a, b) ) ,
68+ EitherOrBoth :: Both ( a, b) => Some ( ( a, b) ) ,
7169 _ => None ,
7270 }
7371 }
7472
7573 /// Converts from `&EitherOrBoth<A, B>` to `EitherOrBoth<&A, &B>`.
7674 pub fn as_ref ( & self ) -> EitherOrBoth < & A , & B > {
7775 match * self {
78- Left ( ref left) => Left ( left) ,
79- Right ( ref right) => Right ( right) ,
80- Both ( ref left, ref right) => Both ( left, right) ,
76+ EitherOrBoth :: Left ( ref left) => EitherOrBoth :: Left ( left) ,
77+ EitherOrBoth :: Right ( ref right) => EitherOrBoth :: Right ( right) ,
78+ EitherOrBoth :: Both ( ref left, ref right) => EitherOrBoth :: Both ( left, right) ,
8179 }
8280 }
8381
8482 /// Converts from `&mut EitherOrBoth<A, B>` to `EitherOrBoth<&mut A, &mut B>`.
8583 pub fn as_mut ( & mut self ) -> EitherOrBoth < & mut A , & mut B > {
8684 match * self {
87- Left ( ref mut left) => Left ( left) ,
88- Right ( ref mut right) => Right ( right) ,
89- Both ( ref mut left, ref mut right) => Both ( left, right) ,
85+ EitherOrBoth :: Left ( ref mut left) => EitherOrBoth :: Left ( left) ,
86+ EitherOrBoth :: Right ( ref mut right) => EitherOrBoth :: Right ( right) ,
87+ EitherOrBoth :: Both ( ref mut left, ref mut right) => EitherOrBoth :: Both ( left, right) ,
9088 }
9189 }
9290
9391 /// Convert `EitherOrBoth<A, B>` to `EitherOrBoth<B, A>`.
9492 pub fn flip ( self ) -> EitherOrBoth < B , A > {
9593 match self {
96- Left ( a) => Right ( a) ,
97- Right ( b) => Left ( b) ,
98- Both ( a, b) => Both ( b, a) ,
94+ EitherOrBoth :: Left ( a) => EitherOrBoth :: Right ( a) ,
95+ EitherOrBoth :: Right ( b) => EitherOrBoth :: Left ( b) ,
96+ EitherOrBoth :: Both ( a, b) => EitherOrBoth :: Both ( b, a) ,
9997 }
10098 }
10199
@@ -106,9 +104,9 @@ impl<A, B> EitherOrBoth<A, B> {
106104 F : FnOnce ( A ) -> M ,
107105 {
108106 match self {
109- Both ( a, b) => Both ( f ( a) , b) ,
110- Left ( a) => Left ( f ( a) ) ,
111- Right ( b) => Right ( b) ,
107+ EitherOrBoth :: Both ( a, b) => EitherOrBoth :: Both ( f ( a) , b) ,
108+ EitherOrBoth :: Left ( a) => EitherOrBoth :: Left ( f ( a) ) ,
109+ EitherOrBoth :: Right ( b) => EitherOrBoth :: Right ( b) ,
112110 }
113111 }
114112
@@ -119,9 +117,9 @@ impl<A, B> EitherOrBoth<A, B> {
119117 F : FnOnce ( B ) -> M ,
120118 {
121119 match self {
122- Left ( a) => Left ( a) ,
123- Right ( b) => Right ( f ( b) ) ,
124- Both ( a, b) => Both ( a, f ( b) ) ,
120+ EitherOrBoth :: Left ( a) => EitherOrBoth :: Left ( a) ,
121+ EitherOrBoth :: Right ( b) => EitherOrBoth :: Right ( f ( b) ) ,
122+ EitherOrBoth :: Both ( a, b) => EitherOrBoth :: Both ( a, f ( b) ) ,
125123 }
126124 }
127125
@@ -134,9 +132,9 @@ impl<A, B> EitherOrBoth<A, B> {
134132 G : FnOnce ( B ) -> R ,
135133 {
136134 match self {
137- Left ( a) => Left ( f ( a) ) ,
138- Right ( b) => Right ( g ( b) ) ,
139- Both ( a, b) => Both ( f ( a) , g ( b) ) ,
135+ EitherOrBoth :: Left ( a) => EitherOrBoth :: Left ( f ( a) ) ,
136+ EitherOrBoth :: Right ( b) => EitherOrBoth :: Right ( g ( b) ) ,
137+ EitherOrBoth :: Both ( a, b) => EitherOrBoth :: Both ( f ( a) , g ( b) ) ,
140138 }
141139 }
142140
@@ -147,8 +145,8 @@ impl<A, B> EitherOrBoth<A, B> {
147145 F : FnOnce ( A ) -> EitherOrBoth < L , B > ,
148146 {
149147 match self {
150- Left ( a) | Both ( a, _) => f ( a) ,
151- Right ( b) => Right ( b) ,
148+ EitherOrBoth :: Left ( a) | EitherOrBoth :: Both ( a, _) => f ( a) ,
149+ EitherOrBoth :: Right ( b) => EitherOrBoth :: Right ( b) ,
152150 }
153151 }
154152
@@ -159,8 +157,8 @@ impl<A, B> EitherOrBoth<A, B> {
159157 F : FnOnce ( B ) -> EitherOrBoth < A , R > ,
160158 {
161159 match self {
162- Left ( a) => Left ( a) ,
163- Right ( b) | Both ( _, b) => f ( b) ,
160+ EitherOrBoth :: Left ( a) => EitherOrBoth :: Left ( a) ,
161+ EitherOrBoth :: Right ( b) | EitherOrBoth :: Both ( _, b) => f ( b) ,
164162 }
165163 }
166164
@@ -185,9 +183,9 @@ impl<A, B> EitherOrBoth<A, B> {
185183 /// ```
186184 pub fn or ( self , l : A , r : B ) -> ( A , B ) {
187185 match self {
188- Left ( inner_l) => ( inner_l, r) ,
189- Right ( inner_r) => ( l, inner_r) ,
190- Both ( inner_l, inner_r) => ( inner_l, inner_r) ,
186+ EitherOrBoth :: Left ( inner_l) => ( inner_l, r) ,
187+ EitherOrBoth :: Right ( inner_r) => ( l, inner_r) ,
188+ EitherOrBoth :: Both ( inner_l, inner_r) => ( inner_l, inner_r) ,
191189 }
192190 }
193191
@@ -222,9 +220,9 @@ impl<A, B> EitherOrBoth<A, B> {
222220 /// ```
223221 pub fn or_else < L : FnOnce ( ) -> A , R : FnOnce ( ) -> B > ( self , l : L , r : R ) -> ( A , B ) {
224222 match self {
225- Left ( inner_l) => ( inner_l, r ( ) ) ,
226- Right ( inner_r) => ( l ( ) , inner_r) ,
227- Both ( inner_l, inner_r) => ( inner_l, inner_r) ,
223+ EitherOrBoth :: Left ( inner_l) => ( inner_l, r ( ) ) ,
224+ EitherOrBoth :: Right ( inner_r) => ( l ( ) , inner_r) ,
225+ EitherOrBoth :: Both ( inner_l, inner_r) => ( inner_l, inner_r) ,
228226 }
229227 }
230228}
@@ -236,9 +234,9 @@ impl<T> EitherOrBoth<T, T> {
236234 F : FnOnce ( T , T ) -> T ,
237235 {
238236 match self {
239- Left ( a) => a,
240- Right ( b) => b,
241- Both ( a, b) => f ( a, b) ,
237+ EitherOrBoth :: Left ( a) => a,
238+ EitherOrBoth :: Right ( b) => b,
239+ EitherOrBoth :: Both ( a, b) => f ( a, b) ,
242240 }
243241 }
244242}
@@ -248,7 +246,7 @@ impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B> {
248246 match self {
249247 EitherOrBoth :: Left ( l) => Some ( Either :: Left ( l) ) ,
250248 EitherOrBoth :: Right ( r) => Some ( Either :: Right ( r) ) ,
251- _ => None ,
249+ EitherOrBoth :: Both ( .. ) => None ,
252250 }
253251 }
254252}
0 commit comments