1
- use crate :: EitherOrBoth :: * ;
2
-
3
1
use either:: Either ;
4
2
5
3
/// Value that either holds a single A or B, or both.
@@ -28,7 +26,7 @@ impl<A, B> EitherOrBoth<A, B> {
28
26
/// Exclusive version of [`has_left`](EitherOrBoth::has_left).
29
27
pub fn is_left ( & self ) -> bool {
30
28
match * self {
31
- Left ( _) => true ,
29
+ EitherOrBoth :: Left ( _) => true ,
32
30
_ => false ,
33
31
}
34
32
}
@@ -37,7 +35,7 @@ impl<A, B> EitherOrBoth<A, B> {
37
35
/// Exclusive version of [`has_right`](EitherOrBoth::has_right).
38
36
pub fn is_right ( & self ) -> bool {
39
37
match * self {
40
- Right ( _) => true ,
38
+ EitherOrBoth :: Right ( _) => true ,
41
39
_ => false ,
42
40
}
43
41
}
@@ -51,51 +49,51 @@ impl<A, B> EitherOrBoth<A, B> {
51
49
/// If `Left`, or `Both`, return `Some` with the left value, otherwise, return `None`.
52
50
pub fn left ( self ) -> Option < A > {
53
51
match self {
54
- Left ( left) | Both ( left, _) => Some ( left) ,
55
- _ => None ,
52
+ EitherOrBoth :: Left ( left) | EitherOrBoth :: Both ( left, _) => Some ( left) ,
53
+ EitherOrBoth :: Right ( _ ) => None ,
56
54
}
57
55
}
58
56
59
57
/// If `Right`, or `Both`, return `Some` with the right value, otherwise, return `None`.
60
58
pub fn right ( self ) -> Option < B > {
61
59
match self {
62
- Right ( right) | Both ( _, right) => Some ( right) ,
63
- _ => None ,
60
+ EitherOrBoth :: Right ( right) | EitherOrBoth :: Both ( _, right) => Some ( right) ,
61
+ EitherOrBoth :: Left ( _ ) => None ,
64
62
}
65
63
}
66
64
67
65
/// If Both, return `Some` tuple containing left and right.
68
66
pub fn both ( self ) -> Option < ( A , B ) > {
69
67
match self {
70
- Both ( a, b) => Some ( ( a, b) ) ,
68
+ EitherOrBoth :: Both ( a, b) => Some ( ( a, b) ) ,
71
69
_ => None ,
72
70
}
73
71
}
74
72
75
73
/// Converts from `&EitherOrBoth<A, B>` to `EitherOrBoth<&A, &B>`.
76
74
pub fn as_ref ( & self ) -> EitherOrBoth < & A , & B > {
77
75
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) ,
81
79
}
82
80
}
83
81
84
82
/// Converts from `&mut EitherOrBoth<A, B>` to `EitherOrBoth<&mut A, &mut B>`.
85
83
pub fn as_mut ( & mut self ) -> EitherOrBoth < & mut A , & mut B > {
86
84
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) ,
90
88
}
91
89
}
92
90
93
91
/// Convert `EitherOrBoth<A, B>` to `EitherOrBoth<B, A>`.
94
92
pub fn flip ( self ) -> EitherOrBoth < B , A > {
95
93
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) ,
99
97
}
100
98
}
101
99
@@ -106,9 +104,9 @@ impl<A, B> EitherOrBoth<A, B> {
106
104
F : FnOnce ( A ) -> M ,
107
105
{
108
106
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) ,
112
110
}
113
111
}
114
112
@@ -119,9 +117,9 @@ impl<A, B> EitherOrBoth<A, B> {
119
117
F : FnOnce ( B ) -> M ,
120
118
{
121
119
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) ) ,
125
123
}
126
124
}
127
125
@@ -134,9 +132,9 @@ impl<A, B> EitherOrBoth<A, B> {
134
132
G : FnOnce ( B ) -> R ,
135
133
{
136
134
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) ) ,
140
138
}
141
139
}
142
140
@@ -147,8 +145,8 @@ impl<A, B> EitherOrBoth<A, B> {
147
145
F : FnOnce ( A ) -> EitherOrBoth < L , B > ,
148
146
{
149
147
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) ,
152
150
}
153
151
}
154
152
@@ -159,8 +157,8 @@ impl<A, B> EitherOrBoth<A, B> {
159
157
F : FnOnce ( B ) -> EitherOrBoth < A , R > ,
160
158
{
161
159
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) ,
164
162
}
165
163
}
166
164
@@ -185,9 +183,9 @@ impl<A, B> EitherOrBoth<A, B> {
185
183
/// ```
186
184
pub fn or ( self , l : A , r : B ) -> ( A , B ) {
187
185
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) ,
191
189
}
192
190
}
193
191
@@ -222,9 +220,9 @@ impl<A, B> EitherOrBoth<A, B> {
222
220
/// ```
223
221
pub fn or_else < L : FnOnce ( ) -> A , R : FnOnce ( ) -> B > ( self , l : L , r : R ) -> ( A , B ) {
224
222
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) ,
228
226
}
229
227
}
230
228
}
@@ -236,9 +234,9 @@ impl<T> EitherOrBoth<T, T> {
236
234
F : FnOnce ( T , T ) -> T ,
237
235
{
238
236
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) ,
242
240
}
243
241
}
244
242
}
@@ -248,7 +246,7 @@ impl<A, B> Into<Option<Either<A, B>>> for EitherOrBoth<A, B> {
248
246
match self {
249
247
EitherOrBoth :: Left ( l) => Some ( Either :: Left ( l) ) ,
250
248
EitherOrBoth :: Right ( r) => Some ( Either :: Right ( r) ) ,
251
- _ => None ,
249
+ EitherOrBoth :: Both ( .. ) => None ,
252
250
}
253
251
}
254
252
}
0 commit comments