Skip to content

Commit da318f2

Browse files
committed
---
yaml --- r: 143324 b: refs/heads/try2 c: 4eb95f6 h: refs/heads/master v: v3
1 parent 8f10ac1 commit da318f2

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 225f1c760d998b2f26107c3938d4ca8baa57c6c0
8+
refs/heads/try2: 4eb95f6d1c22419b50980d0bf8effc6e2f22feb5
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/result.rs

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,6 @@ pub fn get_err<T, U: Clone>(res: &Result<T, U>) -> U {
6262
}
6363
}
6464

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-
8065
/**
8166
* Convert to the `either` type
8267
*
@@ -134,27 +119,8 @@ pub fn chain_err<T, U, V>(
134119
}
135120
}
136121

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+
158124

159125
/**
160126
* Call a function based on a previous result
@@ -164,13 +130,7 @@ pub fn iter<T, E>(res: &Result<T, E>, f: &fn(&T)) {
164130
* This function can be used to pass through a successful result while
165131
* handling an error.
166132
*/
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+
174134

175135
/**
176136
* Call a function based on a previous result
@@ -229,17 +189,58 @@ impl<T, E> Result<T, E> {
229189
}
230190
}
231191

192+
/// Returns true if the result is `ok`
232193
#[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+
}
234200

201+
/// Returns true if the result is `err`
235202
#[inline]
236-
pub fn is_err(&self) -> bool { is_err(self) }
203+
pub fn is_err(&self) -> bool {
204+
!self.is_ok()
205+
}
237206

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+
*/
238221
#[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+
}
240228

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+
*/
241237
#[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+
}
243244

244245
#[inline]
245246
pub fn unwrap(self) -> T { unwrap(self) }

0 commit comments

Comments
 (0)