Skip to content

Commit b644ddd

Browse files
MaikKleinerickt
authored andcommitted
---
yaml --- r: 143326 b: refs/heads/try2 c: f6bcf5d h: refs/heads/master v: v3
1 parent 22c7e5d commit b644ddd

File tree

5 files changed

+55
-88
lines changed

5 files changed

+55
-88
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: e308167a2fe558924fcebcc99358c057ae0b90b4
8+
refs/heads/try2: f6bcf5d5f11a24930c8b3eea4269ba0df583b5cf
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/metadata/filesearch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn get_rustpkg_root() -> Result<Path, ~str> {
147147
}
148148

149149
pub fn get_rustpkg_root_nearest() -> Result<Path, ~str> {
150-
do result::chain(get_rustpkg_root()) |p| {
150+
do get_rustpkg_root().chain |p| {
151151
let cwd = os::getcwd();
152152
let cwd_rustpkg = cwd.push(".rustpkg");
153153
let rustpkg_is_non_root_file =
@@ -173,13 +173,13 @@ pub fn get_rustpkg_root_nearest() -> Result<Path, ~str> {
173173
}
174174

175175
fn get_rustpkg_lib_path() -> Result<Path, ~str> {
176-
do result::chain(get_rustpkg_root()) |p| {
176+
do get_rustpkg_root().chain |p| {
177177
result::Ok(p.push(libdir()))
178178
}
179179
}
180180

181181
fn get_rustpkg_lib_path_nearest() -> Result<Path, ~str> {
182-
do result::chain(get_rustpkg_root_nearest()) |p| {
182+
do get_rustpkg_root_nearest().chain |p| {
183183
result::Ok(p.push(libdir()))
184184
}
185185
}

branches/try2/src/librustdoc/config.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,36 +138,30 @@ fn config_from_opts(
138138

139139
let config = default_config(input_crate);
140140
let result = result::Ok(config);
141-
let result = do result::chain(result) |config| {
141+
let result = do result.chain |config| {
142142
let output_dir = getopts::opt_maybe_str(matches, opt_output_dir());
143143
let output_dir = output_dir.map(|s| Path(*s));
144144
result::Ok(Config {
145145
output_dir: output_dir.get_or_default(config.output_dir.clone()),
146146
.. config
147147
})
148148
};
149-
let result = do result::chain(result) |config| {
150-
let output_format = getopts::opt_maybe_str(
151-
matches, opt_output_format());
152-
do output_format.map_default(result::Ok(config.clone()))
153-
|output_format| {
154-
do result::chain(parse_output_format(*output_format))
155-
|output_format| {
156-
149+
let result = do result.chain |config| {
150+
let output_format = getopts::opt_maybe_str(matches, opt_output_format());
151+
do output_format.map_default(result::Ok(config.clone())) |output_format| {
152+
do parse_output_format(*output_format).chain |output_format| {
157153
result::Ok(Config {
158154
output_format: output_format,
159155
.. config.clone()
160156
})
161157
}
162158
}
163159
};
164-
let result = do result::chain(result) |config| {
160+
let result = do result.chain |config| {
165161
let output_style =
166162
getopts::opt_maybe_str(matches, opt_output_style());
167-
do output_style.map_default(result::Ok(config.clone()))
168-
|output_style| {
169-
do result::chain(parse_output_style(*output_style))
170-
|output_style| {
163+
do output_style.map_default(result::Ok(config.clone())) |output_style| {
164+
do parse_output_style(*output_style).chain |output_style| {
171165
result::Ok(Config {
172166
output_style: output_style,
173167
.. config.clone()
@@ -176,11 +170,11 @@ fn config_from_opts(
176170
}
177171
};
178172
let process_output = Cell::new(process_output);
179-
let result = do result::chain(result) |config| {
173+
let result = do result.chain |config| {
180174
let pandoc_cmd = getopts::opt_maybe_str(matches, opt_pandoc_cmd());
181175
let pandoc_cmd = maybe_find_pandoc(
182176
&config, pandoc_cmd, process_output.take());
183-
do result::chain(pandoc_cmd) |pandoc_cmd| {
177+
do pandoc_cmd.chain |pandoc_cmd| {
184178
result::Ok(Config {
185179
pandoc_cmd: pandoc_cmd,
186180
.. config.clone()

branches/try2/src/libstd/io.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,21 +1726,21 @@ pub fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
17261726
}
17271727

17281728
pub fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
1729-
result::chain(read_whole_file(file), |bytes| {
1729+
do read_whole_file(file).chain |bytes| {
17301730
if str::is_utf8(bytes) {
17311731
result::Ok(str::from_bytes(bytes))
17321732
} else {
17331733
result::Err(file.to_str() + " is not UTF-8")
17341734
}
1735-
})
1735+
}
17361736
}
17371737

17381738
// FIXME (#2004): implement this in a low-level way. Going through the
17391739
// abstractions is pointless.
17401740
pub fn read_whole_file(file: &Path) -> Result<~[u8], ~str> {
1741-
result::chain(file_reader(file), |rdr| {
1741+
do file_reader(file).chain |rdr| {
17421742
result::Ok(rdr.read_whole_stream())
1743-
})
1743+
}
17441744
}
17451745

17461746
// fsync related
@@ -1851,10 +1851,10 @@ mod tests {
18511851
~"A hoopy frood who really knows where his towel is.";
18521852
debug!(frood.clone());
18531853
{
1854-
let out: @io::Writer = io::file_writer(tmpfile, [io::Create, io::Truncate]).unwrap();
1854+
let out = io::file_writer(tmpfile, [io::Create, io::Truncate]).unwrap();
18551855
out.write_str(frood);
18561856
}
1857-
let inp: @io::Reader = io::file_reader(tmpfile).unwrap();
1857+
let inp = io::file_reader(tmpfile).unwrap();
18581858
let frood2: ~str = inp.read_c_str();
18591859
debug!(frood2.clone());
18601860
assert_eq!(frood, frood2);

branches/try2/src/libstd/result.rs

Lines changed: 35 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -77,61 +77,6 @@ pub fn to_either<T:Clone,U:Clone>(res: &Result<U, T>)
7777
}
7878
}
7979

80-
/**
81-
* Call a function based on a previous result
82-
*
83-
* If `res` is `ok` then the value is extracted and passed to `op` whereupon
84-
* `op`s result is returned. if `res` is `err` then it is immediately
85-
* returned. This function can be used to compose the results of two
86-
* functions.
87-
*
88-
* Example:
89-
*
90-
* let res = chain(read_file(file)) { |buf|
91-
* ok(parse_bytes(buf))
92-
* }
93-
*/
94-
#[inline]
95-
pub fn chain<T, U, V>(res: Result<T, V>, op: &fn(T)
96-
-> Result<U, V>) -> Result<U, V> {
97-
match res {
98-
Ok(t) => op(t),
99-
Err(e) => Err(e)
100-
}
101-
}
102-
103-
/**
104-
* Call a function based on a previous result
105-
*
106-
* If `res` is `err` then the value is extracted and passed to `op`
107-
* whereupon `op`s result is returned. if `res` is `ok` then it is
108-
* immediately returned. This function can be used to pass through a
109-
* successful result while handling an error.
110-
*/
111-
#[inline]
112-
pub fn chain_err<T, U, V>(
113-
res: Result<T, V>,
114-
op: &fn(t: V) -> Result<T, U>)
115-
-> Result<T, U> {
116-
match res {
117-
Ok(t) => Ok(t),
118-
Err(v) => op(v)
119-
}
120-
}
121-
122-
123-
124-
125-
/**
126-
* Call a function based on a previous result
127-
*
128-
* If `res` is `err` then the value is extracted and passed to `op` whereupon
129-
* `op`s result is returned. if `res` is `ok` then it is immediately returned.
130-
* This function can be used to pass through a successful result while
131-
* handling an error.
132-
*/
133-
134-
13580
/**
13681
* Call a function based on a previous result
13782
*
@@ -208,7 +153,7 @@ impl<T, E> Result<T, E> {
208153
* Call a function based on a previous result
209154
*
210155
* 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
156+
* `op`s result is returned. if `*self` is `err` then it is immediately
212157
* returned. This function can be used to compose the results of two
213158
* functions.
214159
*
@@ -230,7 +175,7 @@ impl<T, E> Result<T, E> {
230175
* Call a function based on a previous result
231176
*
232177
* 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.
178+
* `op`s result is returned. if `*self` is `ok` then it is immediately returned.
234179
* This function can be used to pass through a successful result while
235180
* handling an error.
236181
*/
@@ -260,14 +205,42 @@ impl<T, E> Result<T, E> {
260205
}
261206
}
262207

208+
/**
209+
* Call a function based on a previous result
210+
*
211+
* If `self` is `ok` then the value is extracted and passed to `op` whereupon
212+
* `op`s result is returned. if `self` is `err` then it is immediately
213+
* returned. This function can be used to compose the results of two
214+
* functions.
215+
*
216+
* Example:
217+
*
218+
* let res = read_file(file).chain(op) { |buf|
219+
* ok(parse_bytes(buf))
220+
* }
221+
*/
263222
#[inline]
264223
pub fn chain<U>(self, op: &fn(T) -> Result<U,E>) -> Result<U,E> {
265-
chain(self, op)
224+
match self {
225+
Ok(t) => op(t),
226+
Err(e) => Err(e)
227+
}
266228
}
267229

230+
/**
231+
* Call a function based on a previous result
232+
*
233+
* If `self` is `err` then the value is extracted and passed to `op`
234+
* whereupon `op`s result is returned. if `self` is `ok` then it is
235+
* immediately returned. This function can be used to pass through a
236+
* successful result while handling an error.
237+
*/
268238
#[inline]
269239
pub fn chain_err<F>(self, op: &fn(E) -> Result<T,F>) -> Result<T,F> {
270-
chain_err(self, op)
240+
match self {
241+
Ok(t) => Ok(t),
242+
Err(v) => op(v)
243+
}
271244
}
272245
}
273246

@@ -390,7 +363,7 @@ pub fn iter_vec2<S,T,U>(ss: &[S], ts: &[T],
390363

391364
#[cfg(test)]
392365
mod tests {
393-
use result::{Err, Ok, Result, chain, get, get_err};
366+
use result::{Err, Ok, Result, get, get_err};
394367
use result;
395368

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

404377
#[test]
405378
pub fn chain_success() {
406-
assert_eq!(get(&chain(op1(), op2)), 667u);
379+
assert_eq!(get(&(op1().chain(op2))), 667u);
407380
}
408381

409382
#[test]
410383
pub fn chain_failure() {
411-
assert_eq!(get_err(&chain(op3(), op2)), ~"sadface");
384+
assert_eq!(get_err(&op3().chain( op2)), ~"sadface");
412385
}
413386
414387
#[test]

0 commit comments

Comments
 (0)