@@ -35,8 +35,8 @@ impl<T, E> Result<T, E> {
35
35
/**
36
36
* Convert to the `either` type
37
37
*
38
- * `ok ` result variants are converted to `either::right ` variants, `err `
39
- * result variants are converted to `either::left `.
38
+ * `Ok ` result variants are converted to `either::Right ` variants, `Err `
39
+ * result variants are converted to `either::Left `.
40
40
*/
41
41
#[ inline]
42
42
pub fn to_either ( self ) -> Either < E , T > {
@@ -56,13 +56,12 @@ impl<T, E> Result<T, E> {
56
56
#[ inline]
57
57
pub fn get_ref < ' a > ( & ' a self ) -> & ' a T {
58
58
match * self {
59
- Ok ( ref t) => t,
60
- Err ( ref the_err) =>
61
- fail ! ( "get_ref called on error result: %?" , * the_err)
59
+ Ok ( ref t) => t,
60
+ Err ( ref e) => fail ! ( "get_ref called on `Err` result: %?" , * e) ,
62
61
}
63
62
}
64
63
65
- /// Returns true if the result is `ok `
64
+ /// Returns true if the result is `Ok `
66
65
#[ inline]
67
66
pub fn is_ok ( & self ) -> bool {
68
67
match * self {
@@ -71,7 +70,7 @@ impl<T, E> Result<T, E> {
71
70
}
72
71
}
73
72
74
- /// Returns true if the result is `err `
73
+ /// Returns true if the result is `Err `
75
74
#[ inline]
76
75
pub fn is_err ( & self ) -> bool {
77
76
!self . is_ok ( )
@@ -80,99 +79,99 @@ impl<T, E> Result<T, E> {
80
79
/**
81
80
* Call a method based on a previous result
82
81
*
83
- * If `* self` is `ok ` then the value is extracted and passed to `op` whereupon
84
- * `op`s result is returned. if `* self` is `err ` then it is immediately
85
- * returned. This function can be used to compose the results of two
86
- * functions.
82
+ * If `self` is `Ok ` then the value is extracted and passed to `op`
83
+ * whereupon `op`s result is returned. if `self` is `Err ` then it is
84
+ * immediately returned. This function can be used to compose the results
85
+ * of two functions.
87
86
*
88
87
* Example:
89
88
*
90
- * read_file(file).iter() { |buf|
89
+ * do read_file(file).iter |buf| {
91
90
* print_buf(buf)
92
91
* }
93
92
*/
94
93
#[ inline]
95
94
pub fn iter ( & self , f : & fn ( & T ) ) {
96
95
match * self {
97
96
Ok ( ref t) => f ( t) ,
98
- Err ( _) => ( )
97
+ Err ( _) => ( ) ,
99
98
}
100
99
}
101
100
102
101
/**
103
102
* Call a method based on a previous result
104
103
*
105
- * If `* self` is `err ` then the value is extracted and passed to `op` whereupon
106
- * `op`s result is returned. if `* self` is `ok ` then it is immediately returned.
107
- * This function can be used to pass through a successful result while
108
- * handling an error.
104
+ * If `self` is `Err ` then the value is extracted and passed to `op`
105
+ * whereupon `op`s result is returned. if `self` is `Ok ` then it is
106
+ * immediately returned. This function can be used to pass through a
107
+ * successful result while handling an error.
109
108
*/
110
109
#[ inline]
111
110
pub fn iter_err ( & self , f : & fn ( & E ) ) {
112
111
match * self {
113
112
Ok ( _) => ( ) ,
114
- Err ( ref e) => f ( e)
113
+ Err ( ref e) => f ( e) ,
115
114
}
116
115
}
117
116
118
- /// Unwraps a result, assuming it is an `ok (T)`
117
+ /// Unwraps a result, assuming it is an `Ok (T)`
119
118
#[ inline]
120
119
pub fn unwrap ( self ) -> T {
121
120
match self {
122
121
Ok ( t) => t,
123
- Err ( _) => fail ! ( "unwrap called on an err result" )
122
+ Err ( _) => fail ! ( "unwrap called on an `Err` result" ) ,
124
123
}
125
124
}
126
125
127
- /// Unwraps a result, assuming it is an `err (U)`
126
+ /// Unwraps a result, assuming it is an `Err (U)`
128
127
#[ inline]
129
128
pub fn unwrap_err ( self ) -> E {
130
129
match self {
131
- Err ( u ) => u ,
132
- Ok ( _) => fail ! ( "unwrap called on an ok result" )
130
+ Err ( e ) => e ,
131
+ Ok ( _) => fail ! ( "unwrap called on an `Ok` result" ) ,
133
132
}
134
133
}
135
134
136
135
/**
137
136
* Call a method based on a previous result
138
137
*
139
- * If `self` is `ok ` then the value is extracted and passed to `op` whereupon
140
- * `op`s result is returned. if `self` is `err ` then it is immediately
141
- * returned. This function can be used to compose the results of two
142
- * functions.
138
+ * If `self` is `Ok ` then the value is extracted and passed to `op`
139
+ * whereupon `op`s result is returned. if `self` is `Err ` then it is
140
+ * immediately returned. This function can be used to compose the results
141
+ * of two functions.
143
142
*
144
143
* Example:
145
144
*
146
- * let res = do read_file(file).chain |buf| {
147
- * ok (parse_bytes(buf))
145
+ * let res = do read_file(file) |buf| {
146
+ * Ok (parse_bytes(buf))
148
147
* };
149
148
*/
150
149
#[ inline]
151
- pub fn chain < U > ( self , op : & fn ( T ) -> Result < U , E > ) -> Result < U , E > {
150
+ pub fn chain < U > ( self , op : & fn ( T ) -> Result < U , E > ) -> Result < U , E > {
152
151
match self {
153
152
Ok ( t) => op ( t) ,
154
- Err ( e) => Err ( e)
153
+ Err ( e) => Err ( e) ,
155
154
}
156
155
}
157
156
158
157
/**
159
- * Call a method based on a previous result
160
- *
161
- * If `self` is `err ` then the value is extracted and passed to `op`
162
- * whereupon `op`s result is returned. if `self` is `ok ` then it is
163
- * immediately returned. This function can be used to pass through a
164
- * successful result while handling an error.
165
- */
158
+ * Call a function based on a previous result
159
+ *
160
+ * If `self` is `Err ` then the value is extracted and passed to `op`
161
+ * whereupon `op`s result is returned. if `self` is `Ok ` then it is
162
+ * immediately returned. This function can be used to pass through a
163
+ * successful result while handling an error.
164
+ */
166
165
#[ inline]
167
- pub fn chain_err < F > ( self , op : & fn ( E ) -> Result < T , F > ) -> Result < T , F > {
166
+ pub fn chain_err < F > ( self , op : & fn ( E ) -> Result < T , F > ) -> Result < T , F > {
168
167
match self {
169
168
Ok ( t) => Ok ( t) ,
170
- Err ( v ) => op ( v )
169
+ Err ( e ) => op ( e ) ,
171
170
}
172
171
}
173
172
}
174
173
175
- impl < T : Clone , E > Result < T , E > {
174
+ impl < T : Clone , E > Result < T , E > {
176
175
/**
177
176
* Get the value out of a successful result
178
177
*
@@ -183,18 +182,18 @@ impl<T:Clone,E> Result<T, E> {
183
182
#[ inline]
184
183
pub fn get ( & self ) -> T {
185
184
match * self {
186
- Ok ( ref t) => ( * t ) . clone ( ) ,
187
- Err ( ref e) => fail ! ( "get called on error result: %?" , * e) ,
185
+ Ok ( ref t) => t . clone ( ) ,
186
+ Err ( ref e) => fail ! ( "get called on `Err` result: %?" , * e) ,
188
187
}
189
188
}
190
189
191
190
/**
192
191
* Call a method based on a previous result
193
192
*
194
- * If `* self` is `err ` then the value is extracted and passed to `op` whereupon
195
- * `op`s result is wrapped in an `err ` and returned. if `* self` is `ok` then it
196
- * is immediately returned. This function can be used to pass through a
197
- * successful result while handling an error.
193
+ * If `self` is `Err ` then the value is extracted and passed to `op`
194
+ * whereupon `op`s result is wrapped in an `Err ` and returned. if `self` is
195
+ * `Ok` then it is immediately returned. This function can be used to pass
196
+ * through a successful result while handling an error.
198
197
*/
199
198
#[ inline]
200
199
pub fn map_err < F : Clone > ( & self , op : & fn ( & E ) -> F ) -> Result < T , F > {
@@ -205,7 +204,7 @@ impl<T:Clone,E> Result<T, E> {
205
204
}
206
205
}
207
206
208
- impl < T , E : Clone > Result < T , E > {
207
+ impl < T , E : Clone > Result < T , E > {
209
208
/**
210
209
* Get the value out of an error result
211
210
*
@@ -216,24 +215,24 @@ impl<T, E:Clone> Result<T, E> {
216
215
#[ inline]
217
216
pub fn get_err ( & self ) -> E {
218
217
match * self {
219
- Err ( ref u ) => ( * u ) . clone ( ) ,
220
- Ok ( _) => fail ! ( "get_err called on ok result" ) ,
218
+ Err ( ref e ) => e . clone ( ) ,
219
+ Ok ( _) => fail ! ( "get_err called on `Ok` result" )
221
220
}
222
221
}
223
222
224
223
/**
225
224
* Call a method based on a previous result
226
225
*
227
- * If `res ` is `ok ` then the value is extracted and passed to `op` whereupon
228
- * `op`s result is wrapped in `ok ` and returned. if `res` is `err` then it is
229
- * immediately returned. This function can be used to compose the results of
230
- * two functions.
226
+ * If `self ` is `Ok ` then the value is extracted and passed to `op`
227
+ * whereupon `op`s result is wrapped in `Ok ` and returned. if `self` is
228
+ * `Err` then it is immediately returned. This function can be used to
229
+ * compose the results of two functions.
231
230
*
232
231
* Example:
233
232
*
234
- * let res = read_file(file).map() { |buf|
233
+ * let res = do read_file(file).map |buf| {
235
234
* parse_bytes(buf)
236
- * }) ;
235
+ * };
237
236
*/
238
237
#[ inline]
239
238
pub fn map < U : Clone > ( & self , op : & fn ( & T ) -> U ) -> Result < U , E > {
@@ -254,8 +253,8 @@ impl<T, E:Clone> Result<T, E> {
254
253
* checking for overflow:
255
254
*
256
255
* fn inc_conditionally(x: uint) -> result<uint,str> {
257
- * if x == uint::max_value { return err ("overflow"); }
258
- * else { return ok (x+1u); }
256
+ * if x == uint::max_value { return Err ("overflow"); }
257
+ * else { return Ok (x+1u); }
259
258
* }
260
259
* map(~[1u, 2u, 3u], inc_conditionally).chain {|incd|
261
260
* assert!(incd == ~[2u, 3u, 4u]);
@@ -340,7 +339,6 @@ pub fn iter_vec2<S,T,U>(ss: &[S], ts: &[T],
340
339
return Ok ( ( ) ) ;
341
340
}
342
341
343
-
344
342
#[ cfg( test) ]
345
343
mod tests {
346
344
use result:: { Err , Ok , Result } ;
0 commit comments