@@ -31,37 +31,6 @@ pub enum Result<T, U> {
31
31
Err ( U )
32
32
}
33
33
34
- /**
35
- * Get the value out of a successful result
36
- *
37
- * # Failure
38
- *
39
- * If the result is an error
40
- */
41
- #[ inline]
42
- pub fn get < T : Clone , U > ( res : & Result < T , U > ) -> T {
43
- match * res {
44
- Ok ( ref t) => ( * t) . clone ( ) ,
45
- Err ( ref the_err) =>
46
- fail ! ( "get called on error result: %?" , * the_err)
47
- }
48
- }
49
-
50
- /**
51
- * Get the value out of an error result
52
- *
53
- * # Failure
54
- *
55
- * If the result is not an error
56
- */
57
- #[ inline]
58
- pub fn get_err < T , U : Clone > ( res : & Result < T , U > ) -> U {
59
- match * res {
60
- Err ( ref u) => ( * u) . clone ( ) ,
61
- Ok ( _) => fail ! ( "get_err called on ok result" )
62
- }
63
- }
64
-
65
34
/**
66
35
* Convert to the `either` type
67
36
*
@@ -245,8 +214,20 @@ impl<T, E> Result<T, E> {
245
214
}
246
215
247
216
impl < T : Clone , E > Result < T , E > {
217
+ /**
218
+ * Get the value out of a successful result
219
+ *
220
+ * # Failure
221
+ *
222
+ * If the result is an error
223
+ */
248
224
#[ inline]
249
- pub fn get ( & self ) -> T { get ( self ) }
225
+ pub fn get ( & self ) -> T {
226
+ match * self {
227
+ Ok ( ref t) => ( * t) . clone ( ) ,
228
+ Err ( ref e) => fail ! ( "get called on error result: %?" , * e) ,
229
+ }
230
+ }
250
231
251
232
#[ inline]
252
233
pub fn map_err < F : Clone > ( & self , op : & fn ( & E ) -> F ) -> Result < T , F > {
@@ -255,8 +236,20 @@ impl<T:Clone,E> Result<T, E> {
255
236
}
256
237
257
238
impl < T , E : Clone > Result < T , E > {
239
+ /**
240
+ * Get the value out of an error result
241
+ *
242
+ * # Failure
243
+ *
244
+ * If the result is not an error
245
+ */
258
246
#[ inline]
259
- pub fn get_err ( & self ) -> E { get_err ( self ) }
247
+ pub fn get_err ( & self ) -> E {
248
+ match * self {
249
+ Err ( ref u) => ( * u) . clone ( ) ,
250
+ Ok ( _) => fail ! ( "get_err called on ok result" ) ,
251
+ }
252
+ }
260
253
261
254
#[ inline]
262
255
pub fn map < U : Clone > ( & self , op : & fn ( & T ) -> U ) -> Result < U , E > {
@@ -363,7 +356,7 @@ pub fn iter_vec2<S,T,U>(ss: &[S], ts: &[T],
363
356
364
357
#[ cfg( test) ]
365
358
mod tests {
366
- use result:: { Err , Ok , Result , get , get_err } ;
359
+ use result:: { Err , Ok , Result } ;
367
360
use result;
368
361
369
362
pub fn op1 ( ) -> result:: Result < int , ~str > { result:: Ok ( 666 ) }
@@ -376,12 +369,12 @@ mod tests {
376
369
377
370
#[ test]
378
371
pub fn chain_success ( ) {
379
- assert_eq ! ( get ( & ( op1( ) . chain( op2) ) ) , 667 u) ;
372
+ assert_eq ! ( op1( ) . chain( op2) . get ( ) , 667 u) ;
380
373
}
381
374
382
375
#[ test]
383
376
pub fn chain_failure ( ) {
384
- assert_eq ! ( get_err ( & op3( ) . chain( op2) ) , ~"sadface");
377
+ assert_eq ! ( op3( ) . chain( op2) . get_err ( ) , ~"sadface");
385
378
}
386
379
387
380
#[test]
0 commit comments