Skip to content

Commit b0aa49a

Browse files
committed
---
yaml --- r: 143328 b: refs/heads/try2 c: aad53cb h: refs/heads/master v: v3
1 parent 24ba556 commit b0aa49a

File tree

2 files changed

+34
-41
lines changed

2 files changed

+34
-41
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: 9dc1de4c9e84a5b8625ff1f066b3f05c39531d9d
8+
refs/heads/try2: aad53cb6e298192cc75cd5769a1b997a3457666c
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: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,45 +46,10 @@ pub fn to_either<T:Clone,U:Clone>(res: &Result<U, T>)
4646
}
4747
}
4848

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-
}
7149

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

8954
impl<T, E> Result<T, E> {
9055
/**
@@ -229,9 +194,20 @@ impl<T:Clone,E> Result<T, E> {
229194
}
230195
}
231196

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+
*/
232205
#[inline]
233206
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+
}
235211
}
236212
}
237213

@@ -251,9 +227,26 @@ impl<T, E:Clone> Result<T, E> {
251227
}
252228
}
253229

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+
*/
254244
#[inline]
255245
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+
}
257250
}
258251
}
259252

0 commit comments

Comments
 (0)