Skip to content

Commit 24ba556

Browse files
MaikKleinerickt
authored andcommitted
---
yaml --- r: 143327 b: refs/heads/try2 c: 9dc1de4 h: refs/heads/master i: 143325: 22c7e5d 143323: 8f10ac1 143319: a65d2d5 143311: 0374c9c 143295: 95d2148 v: v3
1 parent b644ddd commit 24ba556

File tree

2 files changed

+30
-37
lines changed

2 files changed

+30
-37
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: f6bcf5d5f11a24930c8b3eea4269ba0df583b5cf
8+
refs/heads/try2: 9dc1de4c9e84a5b8625ff1f066b3f05c39531d9d
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: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,6 @@ pub enum Result<T, U> {
3131
Err(U)
3232
}
3333

34-
/**
35-
* Get the value out of a successful result
36-
*
37-
* # Failure
38-
*
39-
* If the result is an error
40-
*/
41-
#[inline]
42-
pub fn get<T:Clone,U>(res: &Result<T, U>) -> T {
43-
match *res {
44-
Ok(ref t) => (*t).clone(),
45-
Err(ref the_err) =>
46-
fail!("get called on error result: %?", *the_err)
47-
}
48-
}
49-
50-
/**
51-
* Get the value out of an error result
52-
*
53-
* # Failure
54-
*
55-
* If the result is not an error
56-
*/
57-
#[inline]
58-
pub fn get_err<T, U: Clone>(res: &Result<T, U>) -> U {
59-
match *res {
60-
Err(ref u) => (*u).clone(),
61-
Ok(_) => fail!("get_err called on ok result")
62-
}
63-
}
64-
6534
/**
6635
* Convert to the `either` type
6736
*
@@ -245,8 +214,20 @@ impl<T, E> Result<T, E> {
245214
}
246215

247216
impl<T:Clone,E> Result<T, E> {
217+
/**
218+
* Get the value out of a successful result
219+
*
220+
* # Failure
221+
*
222+
* If the result is an error
223+
*/
248224
#[inline]
249-
pub fn get(&self) -> T { get(self) }
225+
pub fn get(&self) -> T {
226+
match *self {
227+
Ok(ref t) => (*t).clone(),
228+
Err(ref e) => fail!("get called on error result: %?", *e),
229+
}
230+
}
250231

251232
#[inline]
252233
pub fn map_err<F:Clone>(&self, op: &fn(&E) -> F) -> Result<T,F> {
@@ -255,8 +236,20 @@ impl<T:Clone,E> Result<T, E> {
255236
}
256237

257238
impl<T, E:Clone> Result<T, E> {
239+
/**
240+
* Get the value out of an error result
241+
*
242+
* # Failure
243+
*
244+
* If the result is not an error
245+
*/
258246
#[inline]
259-
pub fn get_err(&self) -> E { get_err(self) }
247+
pub fn get_err(&self) -> E {
248+
match *self {
249+
Err(ref u) => (*u).clone(),
250+
Ok(_) => fail!("get_err called on ok result"),
251+
}
252+
}
260253

261254
#[inline]
262255
pub fn map<U:Clone>(&self, op: &fn(&T) -> U) -> Result<U,E> {
@@ -363,7 +356,7 @@ pub fn iter_vec2<S,T,U>(ss: &[S], ts: &[T],
363356

364357
#[cfg(test)]
365358
mod tests {
366-
use result::{Err, Ok, Result, get, get_err};
359+
use result::{Err, Ok, Result};
367360
use result;
368361

369362
pub fn op1() -> result::Result<int, ~str> { result::Ok(666) }
@@ -376,12 +369,12 @@ mod tests {
376369

377370
#[test]
378371
pub fn chain_success() {
379-
assert_eq!(get(&(op1().chain(op2))), 667u);
372+
assert_eq!(op1().chain(op2).get(), 667u);
380373
}
381374

382375
#[test]
383376
pub fn chain_failure() {
384-
assert_eq!(get_err(&op3().chain( op2)), ~"sadface");
377+
assert_eq!(op3().chain( op2).get_err(), ~"sadface");
385378
}
386379
387380
#[test]

0 commit comments

Comments
 (0)