@@ -22,7 +22,6 @@ use vec;
22
22
use vec:: OwnedVector ;
23
23
use to_str:: ToStr ;
24
24
use str:: StrSlice ;
25
- use fmt;
26
25
27
26
/// `Result` is a type that represents either success (`Ok`) or failure (`Err`).
28
27
///
@@ -291,7 +290,7 @@ pub trait AsResult<T, E> {
291
290
292
291
impl < T : Clone , E > option:: ToOption < T > for Result < T , E > {
293
292
#[ inline]
294
- fn to_option ( & self ) -> Option < T > {
293
+ fn to_option ( & self ) -> Option < T > {
295
294
match * self {
296
295
Ok ( ref t) => Some ( t. clone ( ) ) ,
297
296
Err ( _) => None ,
@@ -301,7 +300,7 @@ impl<T: Clone, E> option::ToOption<T> for Result<T, E> {
301
300
302
301
impl < T , E > option:: IntoOption < T > for Result < T , E > {
303
302
#[ inline]
304
- fn into_option ( self ) -> Option < T > {
303
+ fn into_option ( self ) -> Option < T > {
305
304
match self {
306
305
Ok ( t) => Some ( t) ,
307
306
Err ( _) => None ,
@@ -311,7 +310,7 @@ impl<T, E> option::IntoOption<T> for Result<T, E> {
311
310
312
311
impl < T , E > option:: AsOption < T > for Result < T , E > {
313
312
#[ inline]
314
- fn as_option < ' a > ( & ' a self ) -> Option < & ' a T > {
313
+ fn as_option < ' a > ( & ' a self ) -> Option < & ' a T > {
315
314
match * self {
316
315
Ok ( ref t) => Some ( t) ,
317
316
Err ( _) => None ,
@@ -341,7 +340,7 @@ impl<T, E> AsResult<T, E> for Result<T, E> {
341
340
342
341
impl < T : Clone , E : Clone > either:: ToEither < E , T > for Result < T , E > {
343
342
#[ inline]
344
- fn to_either ( & self ) -> either:: Either < E , T > {
343
+ fn to_either ( & self ) -> either:: Either < E , T > {
345
344
match * self {
346
345
Ok ( ref t) => either:: Right ( t. clone ( ) ) ,
347
346
Err ( ref e) => either:: Left ( e. clone ( ) ) ,
@@ -351,7 +350,7 @@ impl<T: Clone, E: Clone> either::ToEither<E, T> for Result<T, E> {
351
350
352
351
impl < T , E > either:: IntoEither < E , T > for Result < T , E > {
353
352
#[ inline]
354
- fn into_either ( self ) -> either:: Either < E , T > {
353
+ fn into_either ( self ) -> either:: Either < E , T > {
355
354
match self {
356
355
Ok ( t) => either:: Right ( t) ,
357
356
Err ( e) => either:: Left ( e) ,
@@ -361,34 +360,14 @@ impl<T, E> either::IntoEither<E, T> for Result<T, E> {
361
360
362
361
impl < T , E > either:: AsEither < E , T > for Result < T , E > {
363
362
#[ inline]
364
- fn as_either < ' a > ( & ' a self ) -> either:: Either < & ' a E , & ' a T > {
363
+ fn as_either < ' a > ( & ' a self ) -> either:: Either < & ' a E , & ' a T > {
365
364
match * self {
366
365
Ok ( ref t) => either:: Right ( t) ,
367
366
Err ( ref e) => either:: Left ( e) ,
368
367
}
369
368
}
370
369
}
371
370
372
- impl < T : ToStr , E : ToStr > ToStr for Result < T , E > {
373
- #[ inline]
374
- fn to_str ( & self ) -> ~str {
375
- match * self {
376
- Ok ( ref t) => format ! ( "Ok({:s})" , t. to_str( ) ) ,
377
- Err ( ref e) => format ! ( "Err({:s})" , e. to_str( ) )
378
- }
379
- }
380
- }
381
-
382
- impl < T : fmt:: Default , E : fmt:: Default > fmt:: Default for Result < T , E > {
383
- #[ inline]
384
- fn fmt ( s : & Result < T , E > , f : & mut fmt:: Formatter ) {
385
- match * s {
386
- Ok ( ref t) => write ! ( f. buf, "Ok({})" , * t) ,
387
- Err ( ref e) => write ! ( f. buf, "Err({})" , * e)
388
- }
389
- }
390
- }
391
-
392
371
/// Takes each element in the iterator: if it is an error, no further
393
372
/// elements are taken, and the error is returned.
394
373
/// Should no error occur, a vector containing the values of each Result
@@ -462,8 +441,6 @@ mod tests {
462
441
use option;
463
442
use str:: OwnedStr ;
464
443
use vec:: ImmutableVector ;
465
- use to_str:: ToStr ;
466
- use fmt:: Default ;
467
444
468
445
pub fn op1 ( ) -> Result < int , ~str > { Ok ( 666 ) }
469
446
pub fn op2 ( ) -> Result < int , ~str > { Err ( ~"sadface") }
@@ -682,22 +659,4 @@ mod tests {
682
659
assert_eq!( ok. as_either( ) . unwrap_right( ) , & 100 ) ;
683
660
assert_eq!( err. as_either( ) . unwrap_left( ) , & 404 ) ;
684
661
}
685
-
686
- #[test]
687
- pub fn test_to_str() {
688
- let ok: Result<int, ~str> = Ok(100);
689
- let err: Result<int, ~str> = Err(~" Err ");
690
-
691
- assert_eq!(ok.to_str(), ~" Ok ( 100 ) ");
692
- assert_eq!(err.to_str(), ~" Err ( Err ) ");
693
- }
694
-
695
- #[test]
696
- pub fn test_fmt_default() {
697
- let ok: Result<int, ~str> = Ok(100);
698
- let err: Result<int, ~str> = Err(~" Err ");
699
-
700
- assert_eq!(format!(" { } ", ok), ~" Ok ( 100 ) ");
701
- assert_eq!(format!(" { } ", err), ~" Err ( Err ) " ) ;
702
- }
703
662
}
0 commit comments