Skip to content

Commit aa2b4a9

Browse files
committed
---
yaml --- r: 143329 b: refs/heads/try2 c: 2a68c71 h: refs/heads/master i: 143327: 24ba556 v: v3
1 parent b0aa49a commit aa2b4a9

File tree

11 files changed

+72
-72
lines changed

11 files changed

+72
-72
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: aad53cb6e298192cc75cd5769a1b997a3457666c
8+
refs/heads/try2: 2a68c719f4a32123fbd428fe280f41af47d00fea
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libextra/json.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,35 +1867,34 @@ mod tests {
18671867
col: 8u,
18681868
msg: @~"EOF while parsing object"}));
18691869
1870-
assert_eq!(result::unwrap(from_str("{}")), mk_object([]));
1871-
assert_eq!(result::unwrap(from_str("{\"a\": 3}")),
1870+
assert_eq!(from_str("{}").unwrap(), mk_object([]));
1871+
assert_eq!(from_str("{\"a\": 3}").unwrap(),
18721872
mk_object([(~"a", Number(3.0f))]));
18731873
1874-
assert_eq!(result::unwrap(from_str(
1875-
"{ \"a\": null, \"b\" : true }")),
1874+
assert_eq!(from_str(
1875+
"{ \"a\": null, \"b\" : true }").unwrap(),
18761876
mk_object([
18771877
(~"a", Null),
18781878
(~"b", Boolean(true))]));
1879-
assert_eq!(result::unwrap(
1880-
from_str("\n{ \"a\": null, \"b\" : true }\n")),
1879+
assert_eq!(from_str("\n{ \"a\": null, \"b\" : true }\n").unwrap(),
18811880
mk_object([
18821881
(~"a", Null),
18831882
(~"b", Boolean(true))]));
1884-
assert_eq!(result::unwrap(from_str(
1885-
"{\"a\" : 1.0 ,\"b\": [ true ]}")),
1883+
assert_eq!(from_str(
1884+
"{\"a\" : 1.0 ,\"b\": [ true ]}").unwrap(),
18861885
mk_object([
18871886
(~"a", Number(1.0)),
18881887
(~"b", List(~[Boolean(true)]))
18891888
]));
1890-
assert_eq!(result::unwrap(from_str(
1889+
assert_eq!(from_str(
18911890
~"{" +
18921891
"\"a\": 1.0, " +
18931892
"\"b\": [" +
18941893
"true," +
18951894
"\"foo\\nbar\", " +
18961895
"{ \"c\": {\"d\": null} } " +
18971896
"]" +
1898-
"}")),
1897+
"}").unwrap(),
18991898
mk_object([
19001899
(~"a", Number(1.0f)),
19011900
(~"b", List(~[

branches/try2/src/libextra/time.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,13 +1132,13 @@ mod tests {
11321132
assert!(test("6", "%w"));
11331133
assert!(test("2009", "%Y"));
11341134
assert!(test("09", "%y"));
1135-
assert!(result::unwrap(strptime("UTC", "%Z")).tm_zone ==
1135+
assert!(strptime("UTC", "%Z").unwrap().tm_zone ==
11361136
~"UTC");
1137-
assert!(result::unwrap(strptime("PST", "%Z")).tm_zone ==
1137+
assert!(strptime("PST", "%Z").unwrap().tm_zone ==
11381138
~"");
1139-
assert!(result::unwrap(strptime("-0000", "%z")).tm_gmtoff ==
1139+
assert!(strptime("-0000", "%z").unwrap().tm_gmtoff ==
11401140
0);
1141-
assert!(result::unwrap(strptime("-0800", "%z")).tm_gmtoff ==
1141+
assert!(strptime("-0800", "%z").unwrap().tm_gmtoff ==
11421142
0);
11431143
assert!(test("%", "%%"));
11441144

branches/try2/src/librustpkg/tests.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ fn git_repo_pkg() -> PkgId {
6262
}
6363

6464
fn writeFile(file_path: &Path, contents: &str) {
65-
let out: @io::Writer =
66-
result::unwrap(io::file_writer(file_path,
67-
[io::Create, io::Truncate]));
65+
let out = io::file_writer(file_path, [io::Create, io::Truncate]).unwrap();
6866
out.write_line(contents);
6967
}
7068

branches/try2/src/libstd/result.rs

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,21 @@ pub enum Result<T, U> {
3131
Err(U)
3232
}
3333

34-
/**
35-
* Convert to the `either` type
36-
*
37-
* `ok` result variants are converted to `either::right` variants, `err`
38-
* result variants are converted to `either::left`.
39-
*/
40-
#[inline]
41-
pub fn to_either<T:Clone,U:Clone>(res: &Result<U, T>)
42-
-> Either<T, U> {
43-
match *res {
44-
Ok(ref res) => either::Right((*res).clone()),
45-
Err(ref fail_) => either::Left((*fail_).clone())
34+
impl<T, E> Result<T, E> {
35+
/**
36+
* Convert to the `either` type
37+
*
38+
* `ok` result variants are converted to `either::right` variants, `err`
39+
* result variants are converted to `either::left`.
40+
*/
41+
#[inline]
42+
pub fn to_either(self)-> Either<E, T>{
43+
match self {
44+
Ok(t) => either::Right(t),
45+
Err(e) => either::Left(e),
46+
}
4647
}
47-
}
48-
49-
50-
5148

52-
53-
54-
impl<T, E> Result<T, E> {
5549
/**
5650
* Get a reference to the value out of a successful result
5751
*
@@ -84,7 +78,7 @@ impl<T, E> Result<T, E> {
8478
}
8579

8680
/**
87-
* Call a function based on a previous result
81+
* Call a method based on a previous result
8882
*
8983
* If `*self` is `ok` then the value is extracted and passed to `op` whereupon
9084
* `op`s result is returned. if `*self` is `err` then it is immediately
@@ -106,7 +100,7 @@ impl<T, E> Result<T, E> {
106100
}
107101

108102
/**
109-
* Call a function based on a previous result
103+
* Call a method based on a previous result
110104
*
111105
* If `*self` is `err` then the value is extracted and passed to `op` whereupon
112106
* `op`s result is returned. if `*self` is `ok` then it is immediately returned.
@@ -140,7 +134,7 @@ impl<T, E> Result<T, E> {
140134
}
141135

142136
/**
143-
* Call a function based on a previous result
137+
* Call a method based on a previous result
144138
*
145139
* If `self` is `ok` then the value is extracted and passed to `op` whereupon
146140
* `op`s result is returned. if `self` is `err` then it is immediately
@@ -149,9 +143,9 @@ impl<T, E> Result<T, E> {
149143
*
150144
* Example:
151145
*
152-
* let res = read_file(file).chain(op) { |buf|
146+
* let res = do read_file(file).chain |buf| {
153147
* ok(parse_bytes(buf))
154-
* }
148+
* };
155149
*/
156150
#[inline]
157151
pub fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
@@ -162,7 +156,7 @@ impl<T, E> Result<T, E> {
162156
}
163157

164158
/**
165-
* Call a function based on a previous result
159+
* Call a method based on a previous result
166160
*
167161
* If `self` is `err` then the value is extracted and passed to `op`
168162
* whereupon `op`s result is returned. if `self` is `ok` then it is
@@ -195,13 +189,13 @@ impl<T:Clone,E> Result<T, E> {
195189
}
196190

197191
/**
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-
*/
192+
* Call a method based on a previous result
193+
*
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.
198+
*/
205199
#[inline]
206200
pub fn map_err<F:Clone>(&self, op: &fn(&E) -> F) -> Result<T,F> {
207201
match *self {
@@ -228,19 +222,19 @@ impl<T, E:Clone> Result<T, E> {
228222
}
229223

230224
/**
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-
*/
225+
* Call a method based on a previous result
226+
*
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.
231+
*
232+
* Example:
233+
*
234+
* let res = read_file(file).map() { |buf|
235+
* parse_bytes(buf)
236+
* });
237+
*/
244238
#[inline]
245239
pub fn map<U:Clone>(&self, op: &fn(&T) -> U) -> Result<U,E> {
246240
match *self {
@@ -351,6 +345,7 @@ pub fn iter_vec2<S,T,U>(ss: &[S], ts: &[T],
351345
mod tests {
352346
use result::{Err, Ok, Result};
353347
use result;
348+
use either;
354349

355350
pub fn op1() -> result::Result<int, ~str> { result::Ok(666) }
356351

@@ -408,4 +403,13 @@ mod tests {
408403
let foo: Result<int, ()> = Ok(100);
409404
assert_eq!(*foo.get_ref(), 100);
410405
}
406+
407+
#[test]
408+
pub fn test_to_either() {
409+
let r: Result<int, ()> = Ok(100);
410+
let err: Result<(), int> = Err(404);
411+
412+
assert_eq!(r.to_either(), either::Right(100));
413+
assert_eq!(err.to_either(), either::Left(404));
414+
}
411415
}

branches/try2/src/test/bench/core-std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn read_line() {
7575
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
7676

7777
for int::range(0, 3) |_i| {
78-
let reader = result::unwrap(io::file_reader(&path));
78+
let reader = io::file_reader(&path).unwrap();
7979
while !reader.eof() {
8080
reader.read_line();
8181
}

branches/try2/src/test/bench/shootout-fasta.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ fn main() {
124124
};
125125

126126
let writer = if os::getenv("RUST_BENCH").is_some() {
127-
result::unwrap(io::file_writer(&Path("./shootout-fasta.data"),
128-
[io::Truncate, io::Create]))
127+
io::file_writer(&Path("./shootout-fasta.data"),
128+
[io::Truncate, io::Create]).unwrap()
129129
} else {
130130
io::stdout()
131131
};

branches/try2/src/test/bench/shootout-k-nucleotide-pipes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn main() {
161161
// get to this massive data set, but include_bin! chokes on it (#2598)
162162
let path = Path(env!("CFG_SRC_DIR"))
163163
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
164-
result::unwrap(io::file_reader(&path))
164+
io::file_reader(&path).unwrap()
165165
} else {
166166
io::stdin()
167167
};

branches/try2/src/test/run-fail/result-get-fail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
use std::result;
1414

1515
fn main() {
16-
error!(result::get(&result::Err::<int,~str>(~"kitty")));
16+
error!(result::Err::<int,~str>(~"kitty").get());
1717
}

branches/try2/src/test/run-pass/cleanup-copy-mode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::task;
1616
fn adder(x: @int, y: @int) -> int { return *x + *y; }
1717
fn failer() -> @int { fail!(); }
1818
pub fn main() {
19-
assert!(result::is_err(&task::try(|| {
19+
assert!(task::try(|| {
2020
adder(@2, failer()); ()
21-
})));
21+
}).is_err());
2222
}

branches/try2/src/test/run-pass/issue-4016.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111

1212
extern mod extra;
1313

14-
use std::result;
1514
use extra::json;
1615
use extra::serialize::Decodable;
1716

1817
trait JD : Decodable<json::Decoder> { }
1918

2019
fn exec<T: JD>() {
21-
let doc = result::unwrap(json::from_str(""));
20+
let doc = json::from_str("").unwrap();
2221
let mut decoder = json::Decoder(doc);
2322
let _v: T = Decodable::decode(&mut decoder);
2423
fail!()

0 commit comments

Comments
 (0)