@@ -62,21 +62,6 @@ pub fn get_err<T, U: Clone>(res: &Result<T, U>) -> U {
62
62
}
63
63
}
64
64
65
- /// Returns true if the result is `ok`
66
- #[ inline]
67
- pub fn is_ok < T , U > ( res : & Result < T , U > ) -> bool {
68
- match * res {
69
- Ok ( _) => true ,
70
- Err ( _) => false
71
- }
72
- }
73
-
74
- /// Returns true if the result is `err`
75
- #[ inline]
76
- pub fn is_err < T , U > ( res : & Result < T , U > ) -> bool {
77
- !is_ok ( res)
78
- }
79
-
80
65
/**
81
66
* Convert to the `either` type
82
67
*
@@ -134,27 +119,8 @@ pub fn chain_err<T, U, V>(
134
119
}
135
120
}
136
121
137
- /**
138
- * Call a function based on a previous result
139
- *
140
- * If `res` is `ok` then the value is extracted and passed to `op` whereupon
141
- * `op`s result is returned. if `res` is `err` then it is immediately
142
- * returned. This function can be used to compose the results of two
143
- * functions.
144
- *
145
- * Example:
146
- *
147
- * iter(read_file(file)) { |buf|
148
- * print_buf(buf)
149
- * }
150
- */
151
- #[ inline]
152
- pub fn iter < T , E > ( res : & Result < T , E > , f : & fn ( & T ) ) {
153
- match * res {
154
- Ok ( ref t) => f ( t) ,
155
- Err ( _) => ( )
156
- }
157
- }
122
+
123
+
158
124
159
125
/**
160
126
* Call a function based on a previous result
@@ -164,13 +130,7 @@ pub fn iter<T, E>(res: &Result<T, E>, f: &fn(&T)) {
164
130
* This function can be used to pass through a successful result while
165
131
* handling an error.
166
132
*/
167
- #[ inline]
168
- pub fn iter_err < T , E > ( res : & Result < T , E > , f : & fn ( & E ) ) {
169
- match * res {
170
- Ok ( _) => ( ) ,
171
- Err ( ref e) => f ( e)
172
- }
173
- }
133
+
174
134
175
135
/**
176
136
* Call a function based on a previous result
@@ -229,17 +189,58 @@ impl<T, E> Result<T, E> {
229
189
}
230
190
}
231
191
192
+ /// Returns true if the result is `ok`
232
193
#[ inline]
233
- pub fn is_ok ( & self ) -> bool { is_ok ( self ) }
194
+ pub fn is_ok ( & self ) -> bool {
195
+ match * self {
196
+ Ok ( _) => true ,
197
+ Err ( _) => false
198
+ }
199
+ }
234
200
201
+ /// Returns true if the result is `err`
235
202
#[ inline]
236
- pub fn is_err ( & self ) -> bool { is_err ( self ) }
203
+ pub fn is_err ( & self ) -> bool {
204
+ !self . is_ok ( )
205
+ }
237
206
207
+ /**
208
+ * Call a function based on a previous result
209
+ *
210
+ * If `*self` is `ok` then the value is extracted and passed to `op` whereupon
211
+ * `op`s result is returned. if `res` is `err` then it is immediately
212
+ * returned. This function can be used to compose the results of two
213
+ * functions.
214
+ *
215
+ * Example:
216
+ *
217
+ * read_file(file).iter() { |buf|
218
+ * print_buf(buf)
219
+ * }
220
+ */
238
221
#[ inline]
239
- pub fn iter ( & self , f : & fn ( & T ) ) { iter ( self , f) }
222
+ pub fn iter ( & self , f : & fn ( & T ) ) {
223
+ match * self {
224
+ Ok ( ref t) => f ( t) ,
225
+ Err ( _) => ( )
226
+ }
227
+ }
240
228
229
+ /**
230
+ * Call a function based on a previous result
231
+ *
232
+ * If `*self` is `err` then the value is extracted and passed to `op` whereupon
233
+ * `op`s result is returned. if `res` is `ok` then it is immediately returned.
234
+ * This function can be used to pass through a successful result while
235
+ * handling an error.
236
+ */
241
237
#[ inline]
242
- pub fn iter_err ( & self , f : & fn ( & E ) ) { iter_err ( self , f) }
238
+ pub fn iter_err ( & self , f : & fn ( & E ) ) {
239
+ match * self {
240
+ Ok ( _) => ( ) ,
241
+ Err ( ref e) => f ( e)
242
+ }
243
+ }
243
244
244
245
#[ inline]
245
246
pub fn unwrap ( self ) -> T { unwrap ( self ) }
0 commit comments