|
13 | 13 | #[allow(missing_doc)]; |
14 | 14 |
|
15 | 15 | use option::{Some, None}; |
16 | | -use option; |
17 | 16 | use clone::Clone; |
18 | 17 | use container::Container; |
19 | 18 | use cmp::Eq; |
20 | 19 | use iter::{Iterator, FilterMap}; |
21 | | -use result::Result; |
22 | | -use result; |
23 | 20 | use str::StrSlice; |
24 | 21 | use vec; |
25 | 22 | use vec::{OwnedVector, ImmutableVector}; |
@@ -105,101 +102,6 @@ impl<L, R> Either<L, R> { |
105 | 102 | } |
106 | 103 | } |
107 | 104 |
|
108 | | -/// A generic trait for converting a value to a `Either` |
109 | | -pub trait ToEither<L, R> { |
110 | | - /// Convert to the `either` type |
111 | | - fn to_either(&self) -> Either<L, R>; |
112 | | -} |
113 | | - |
114 | | -/// A generic trait for converting a value to a `Either` |
115 | | -pub trait IntoEither<L, R> { |
116 | | - /// Convert to the `either` type |
117 | | - fn into_either(self) -> Either<L, R>; |
118 | | -} |
119 | | - |
120 | | -/// A generic trait for converting a value to a `Either` |
121 | | -pub trait AsEither<L, R> { |
122 | | - /// Convert to the `either` type |
123 | | - fn as_either<'a>(&'a self) -> Either<&'a L, &'a R>; |
124 | | -} |
125 | | - |
126 | | -impl<L, R: Clone> option::ToOption<R> for Either<L, R> { |
127 | | - #[inline] |
128 | | - fn to_option(&self)-> option::Option<R> { |
129 | | - match *self { |
130 | | - Left(_) => None, |
131 | | - Right(ref r) => Some(r.clone()), |
132 | | - } |
133 | | - } |
134 | | -} |
135 | | - |
136 | | -impl<L, R> option::IntoOption<R> for Either<L, R> { |
137 | | - #[inline] |
138 | | - fn into_option(self)-> option::Option<R> { |
139 | | - match self { |
140 | | - Left(_) => None, |
141 | | - Right(r) => Some(r), |
142 | | - } |
143 | | - } |
144 | | -} |
145 | | - |
146 | | -impl<L, R> option::AsOption<R> for Either<L, R> { |
147 | | - #[inline] |
148 | | - fn as_option<'a>(&'a self) -> option::Option<&'a R> { |
149 | | - match *self { |
150 | | - Left(_) => None, |
151 | | - Right(ref r) => Some(r), |
152 | | - } |
153 | | - } |
154 | | -} |
155 | | - |
156 | | -impl<L: Clone, R: Clone> result::ToResult<R, L> for Either<L, R> { |
157 | | - #[inline] |
158 | | - fn to_result(&self)-> result::Result<R, L> { |
159 | | - match *self { |
160 | | - Left(ref l) => result::Err(l.clone()), |
161 | | - Right(ref r) => result::Ok(r.clone()), |
162 | | - } |
163 | | - } |
164 | | -} |
165 | | - |
166 | | -impl<L, R> result::IntoResult<R, L> for Either<L, R> { |
167 | | - #[inline] |
168 | | - fn into_result(self)-> result::Result<R, L> { |
169 | | - match self { |
170 | | - Left(l) => result::Err(l), |
171 | | - Right(r) => result::Ok(r), |
172 | | - } |
173 | | - } |
174 | | -} |
175 | | - |
176 | | -impl<L, R> result::AsResult<R, L> for Either<L, R> { |
177 | | - #[inline] |
178 | | - fn as_result<'a>(&'a self) -> result::Result<&'a R, &'a L> { |
179 | | - match *self { |
180 | | - Left(ref l) => result::Err(l), |
181 | | - Right(ref r) => result::Ok(r), |
182 | | - } |
183 | | - } |
184 | | -} |
185 | | - |
186 | | -impl<L: Clone, R: Clone> ToEither<L, R> for Either<L, R> { |
187 | | - fn to_either(&self) -> Either<L, R> { self.clone() } |
188 | | -} |
189 | | - |
190 | | -impl<L, R> IntoEither<L, R> for Either<L, R> { |
191 | | - fn into_either(self) -> Either<L, R> { self } |
192 | | -} |
193 | | - |
194 | | -impl<L, R> AsEither<L, R> for Either<L, R> { |
195 | | - fn as_either<'a>(&'a self) -> Either<&'a L, &'a R> { |
196 | | - match *self { |
197 | | - Left(ref l) => Left(l), |
198 | | - Right(ref r) => Right(r), |
199 | | - } |
200 | | - } |
201 | | -} |
202 | | - |
203 | 105 | /// An iterator yielding the `Left` values of its source |
204 | 106 | pub type Lefts<L, R, Iter> = FilterMap<'static, Either<L, R>, L, Iter>; |
205 | 107 |
|
@@ -251,11 +153,6 @@ pub fn partition<L, R>(eithers: ~[Either<L, R>]) -> (~[L], ~[R]) { |
251 | 153 | mod tests { |
252 | 154 | use super::*; |
253 | 155 |
|
254 | | - use option::{IntoOption, ToOption, AsOption}; |
255 | | - use option; |
256 | | - use result::{IntoResult, ToResult, AsResult}; |
257 | | - use result; |
258 | | - |
259 | 156 | #[test] |
260 | 157 | fn test_either_left() { |
261 | 158 | let val = Left(10); |
@@ -348,88 +245,4 @@ mod tests { |
348 | 245 | assert_eq!(lefts.len(), 0u); |
349 | 246 | assert_eq!(rights.len(), 0u); |
350 | 247 | } |
351 | | - |
352 | | - #[test] |
353 | | - pub fn test_to_option() { |
354 | | - let right: Either<int, int> = Right(100); |
355 | | - let left: Either<int, int> = Left(404); |
356 | | - |
357 | | - assert_eq!(right.to_option(), option::Some(100)); |
358 | | - assert_eq!(left.to_option(), option::None); |
359 | | - } |
360 | | - |
361 | | - #[test] |
362 | | - pub fn test_into_option() { |
363 | | - let right: Either<int, int> = Right(100); |
364 | | - let left: Either<int, int> = Left(404); |
365 | | - |
366 | | - assert_eq!(right.into_option(), option::Some(100)); |
367 | | - assert_eq!(left.into_option(), option::None); |
368 | | - } |
369 | | - |
370 | | - #[test] |
371 | | - pub fn test_as_option() { |
372 | | - let right: Either<int, int> = Right(100); |
373 | | - let left: Either<int, int> = Left(404); |
374 | | - |
375 | | - assert_eq!(right.as_option().unwrap(), &100); |
376 | | - assert_eq!(left.as_option(), option::None); |
377 | | - } |
378 | | - |
379 | | - #[test] |
380 | | - pub fn test_to_result() { |
381 | | - let right: Either<int, int> = Right(100); |
382 | | - let left: Either<int, int> = Left(404); |
383 | | - |
384 | | - assert_eq!(right.to_result(), result::Ok(100)); |
385 | | - assert_eq!(left.to_result(), result::Err(404)); |
386 | | - } |
387 | | - |
388 | | - #[test] |
389 | | - pub fn test_into_result() { |
390 | | - let right: Either<int, int> = Right(100); |
391 | | - let left: Either<int, int> = Left(404); |
392 | | - |
393 | | - assert_eq!(right.into_result(), result::Ok(100)); |
394 | | - assert_eq!(left.into_result(), result::Err(404)); |
395 | | - } |
396 | | - |
397 | | - #[test] |
398 | | - pub fn test_as_result() { |
399 | | - let right: Either<int, int> = Right(100); |
400 | | - let left: Either<int, int> = Left(404); |
401 | | - |
402 | | - let x = 100; |
403 | | - assert_eq!(right.as_result(), result::Ok(&x)); |
404 | | - |
405 | | - let x = 404; |
406 | | - assert_eq!(left.as_result(), result::Err(&x)); |
407 | | - } |
408 | | - |
409 | | - #[test] |
410 | | - pub fn test_to_either() { |
411 | | - let right: Either<int, int> = Right(100); |
412 | | - let left: Either<int, int> = Left(404); |
413 | | - |
414 | | - assert_eq!(right.to_either(), Right(100)); |
415 | | - assert_eq!(left.to_either(), Left(404)); |
416 | | - } |
417 | | - |
418 | | - #[test] |
419 | | - pub fn test_into_either() { |
420 | | - let right: Either<int, int> = Right(100); |
421 | | - let left: Either<int, int> = Left(404); |
422 | | - |
423 | | - assert_eq!(right.into_either(), Right(100)); |
424 | | - assert_eq!(left.into_either(), Left(404)); |
425 | | - } |
426 | | - |
427 | | - #[test] |
428 | | - pub fn test_as_either() { |
429 | | - let right: Either<int, int> = Right(100); |
430 | | - let left: Either<int, int> = Left(404); |
431 | | - |
432 | | - assert_eq!(right.as_either().unwrap_right(), &100); |
433 | | - assert_eq!(left.as_either().unwrap_left(), &404); |
434 | | - } |
435 | 248 | } |
0 commit comments