@@ -46,45 +46,10 @@ pub fn to_either<T:Clone,U:Clone>(res: &Result<U, T>)
46
46
}
47
47
}
48
48
49
- /**
50
- * Call a function based on a previous result
51
- *
52
- * If `res` is `ok` then the value is extracted and passed to `op` whereupon
53
- * `op`s result is wrapped in `ok` and returned. if `res` is `err` then it is
54
- * immediately returned. This function can be used to compose the results of
55
- * two functions.
56
- *
57
- * Example:
58
- *
59
- * let res = map(read_file(file)) { |buf|
60
- * parse_bytes(buf)
61
- * }
62
- */
63
- #[ inline]
64
- pub fn map < T , E : Clone , U : Clone > ( res : & Result < T , E > , op : & fn ( & T ) -> U )
65
- -> Result < U , E > {
66
- match * res {
67
- Ok ( ref t) => Ok ( op ( t) ) ,
68
- Err ( ref e) => Err ( ( * e) . clone ( ) )
69
- }
70
- }
71
49
72
- /**
73
- * Call a function based on a previous result
74
- *
75
- * If `res` is `err` then the value is extracted and passed to `op` whereupon
76
- * `op`s result is wrapped in an `err` and returned. if `res` is `ok` then it
77
- * is immediately returned. This function can be used to pass through a
78
- * successful result while handling an error.
79
- */
80
- #[ inline]
81
- pub fn map_err < T : Clone , E , F : Clone > ( res : & Result < T , E > , op : & fn ( & E ) -> F )
82
- -> Result < T , F > {
83
- match * res {
84
- Ok ( ref t) => Ok ( ( * t) . clone ( ) ) ,
85
- Err ( ref e) => Err ( op ( e) )
86
- }
87
- }
50
+
51
+
52
+
88
53
89
54
impl < T , E > Result < T , E > {
90
55
/**
@@ -229,9 +194,20 @@ impl<T:Clone,E> Result<T, E> {
229
194
}
230
195
}
231
196
197
+ /**
198
+ * Call a function based on a previous result
199
+ *
200
+ * If `*self` is `err` then the value is extracted and passed to `op` whereupon
201
+ * `op`s result is wrapped in an `err` and returned. if `*self` is `ok` then it
202
+ * is immediately returned. This function can be used to pass through a
203
+ * successful result while handling an error.
204
+ */
232
205
#[ inline]
233
206
pub fn map_err < F : Clone > ( & self , op : & fn ( & E ) -> F ) -> Result < T , F > {
234
- map_err ( self , op)
207
+ match * self {
208
+ Ok ( ref t) => Ok ( t. clone ( ) ) ,
209
+ Err ( ref e) => Err ( op ( e) )
210
+ }
235
211
}
236
212
}
237
213
@@ -251,9 +227,26 @@ impl<T, E:Clone> Result<T, E> {
251
227
}
252
228
}
253
229
230
+ /**
231
+ * Call a function based on a previous result
232
+ *
233
+ * If `res` is `ok` then the value is extracted and passed to `op` whereupon
234
+ * `op`s result is wrapped in `ok` and returned. if `res` is `err` then it is
235
+ * immediately returned. This function can be used to compose the results of
236
+ * two functions.
237
+ *
238
+ * Example:
239
+ *
240
+ * let res = map(read_file(file)) { |buf|
241
+ * parse_bytes(buf)
242
+ * }
243
+ */
254
244
#[ inline]
255
245
pub fn map < U : Clone > ( & self , op : & fn ( & T ) -> U ) -> Result < U , E > {
256
- map ( self , op)
246
+ match * self {
247
+ Ok ( ref t) => Ok ( op ( t) ) ,
248
+ Err ( ref e) => Err ( e. clone ( ) )
249
+ }
257
250
}
258
251
}
259
252
0 commit comments