1
Fork 0

Demode core::result

This commit is contained in:
Brian Anderson 2012-09-25 16:23:04 -07:00
parent 62649f0412
commit d05e2ad66c
23 changed files with 153 additions and 145 deletions

View file

@ -460,7 +460,7 @@ fn parse_source(name: ~str, j: json::Json) -> source {
fn try_parse_sources(filename: &Path, sources: map::HashMap<~str, source>) { fn try_parse_sources(filename: &Path, sources: map::HashMap<~str, source>) {
if !os::path_exists(filename) { return; } if !os::path_exists(filename) { return; }
let c = io::read_whole_file_str(filename); let c = io::read_whole_file_str(filename);
match json::from_str(result::get(c)) { match json::from_str(c.get()) {
Ok(json::Dict(j)) => { Ok(json::Dict(j)) => {
for j.each |k, v| { for j.each |k, v| {
sources.insert(k, parse_source(k, v)); sources.insert(k, parse_source(k, v));
@ -579,7 +579,7 @@ fn load_source_info(c: &cargo, src: source) {
let srcfile = dir.push("source.json"); let srcfile = dir.push("source.json");
if !os::path_exists(&srcfile) { return; } if !os::path_exists(&srcfile) { return; }
let srcstr = io::read_whole_file_str(&srcfile); let srcstr = io::read_whole_file_str(&srcfile);
match json::from_str(result::get(srcstr)) { match json::from_str(srcstr.get()) {
Ok(json::Dict(s)) => { Ok(json::Dict(s)) => {
let o = parse_source(src.name, json::Dict(s)); let o = parse_source(src.name, json::Dict(s));
@ -601,7 +601,7 @@ fn load_source_packages(c: &cargo, src: source) {
let pkgfile = dir.push("packages.json"); let pkgfile = dir.push("packages.json");
if !os::path_exists(&pkgfile) { return; } if !os::path_exists(&pkgfile) { return; }
let pkgstr = io::read_whole_file_str(&pkgfile); let pkgstr = io::read_whole_file_str(&pkgfile);
match json::from_str(result::get(pkgstr)) { match json::from_str(pkgstr.get()) {
Ok(json::List(js)) => { Ok(json::List(js)) => {
for (*js).each |j| { for (*js).each |j| {
match *j { match *j {
@ -659,7 +659,7 @@ fn build_cargo_options(argv: ~[~str]) -> options {
fn configure(opts: options) -> cargo { fn configure(opts: options) -> cargo {
let home = match get_cargo_root() { let home = match get_cargo_root() {
Ok(home) => home, Ok(home) => home,
Err(_err) => result::get(get_cargo_sysroot()) Err(_err) => get_cargo_sysroot().get()
}; };
let get_cargo_dir = match opts.mode { let get_cargo_dir = match opts.mode {
@ -668,7 +668,7 @@ fn configure(opts: options) -> cargo {
local_mode => get_cargo_root_nearest local_mode => get_cargo_root_nearest
}; };
let p = result::get(get_cargo_dir()); let p = get_cargo_dir().get();
let sources = map::HashMap(); let sources = map::HashMap();
try_parse_sources(&home.push("sources.json"), sources); try_parse_sources(&home.push("sources.json"), sources);

View file

@ -9,7 +9,7 @@ type expected_error = { line: uint, kind: ~str, msg: ~str };
// Load any test directives embedded in the file // Load any test directives embedded in the file
fn load_errors(testfile: &Path) -> ~[expected_error] { fn load_errors(testfile: &Path) -> ~[expected_error] {
let mut error_patterns = ~[]; let mut error_patterns = ~[];
let rdr = result::get(io::file_reader(testfile)); let rdr = io::file_reader(testfile).get();
let mut line_num = 1u; let mut line_num = 1u;
while !rdr.eof() { while !rdr.eof() {
let ln = rdr.read_line(); let ln = rdr.read_line();

View file

@ -73,7 +73,7 @@ fn is_test_ignored(config: config, testfile: &Path) -> bool {
} }
fn iter_header(testfile: &Path, it: fn(~str) -> bool) -> bool { fn iter_header(testfile: &Path, it: fn(~str) -> bool) -> bool {
let rdr = result::get(io::file_reader(testfile)); let rdr = io::file_reader(testfile).get();
while !rdr.eof() { while !rdr.eof() {
let ln = rdr.read_line(); let ln = rdr.read_line();

View file

@ -109,7 +109,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) {
let rounds = let rounds =
match props.pp_exact { option::Some(_) => 1, option::None => 2 }; match props.pp_exact { option::Some(_) => 1, option::None => 2 };
let mut srcs = ~[result::get(io::read_whole_file_str(testfile))]; let mut srcs = ~[io::read_whole_file_str(testfile).get()];
let mut round = 0; let mut round = 0;
while round < rounds { while round < rounds {
@ -129,7 +129,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) {
match props.pp_exact { match props.pp_exact {
option::Some(file) => { option::Some(file) => {
let filepath = testfile.dir_path().push_rel(&file); let filepath = testfile.dir_path().push_rel(&file);
result::get(io::read_whole_file_str(&filepath)) io::read_whole_file_str(&filepath).get()
} }
option::None => { srcs[vec::len(srcs) - 2u] } option::None => { srcs[vec::len(srcs) - 2u] }
}; };
@ -561,8 +561,8 @@ fn dump_output(config: config, testfile: &Path, out: ~str, err: ~str) {
fn dump_output_file(config: config, testfile: &Path, fn dump_output_file(config: config, testfile: &Path,
out: ~str, extension: ~str) { out: ~str, extension: ~str) {
let outfile = make_out_name(config, testfile, extension); let outfile = make_out_name(config, testfile, extension);
let writer = result::get( let writer =
io::file_writer(&outfile, ~[io::Create, io::Truncate])); io::file_writer(&outfile, ~[io::Create, io::Truncate]).get();
writer.write_str(out); writer.write_str(out);
} }

View file

@ -19,7 +19,7 @@ impl test_mode : cmp::Eq {
fn write_file(filename: &Path, content: ~str) { fn write_file(filename: &Path, content: ~str) {
result::get( result::get(
io::file_writer(filename, ~[io::Create, io::Truncate])) &io::file_writer(filename, ~[io::Create, io::Truncate]))
.write_str(content); .write_str(content);
} }
@ -543,7 +543,7 @@ fn check_convergence(files: &[Path]) {
error!("pp convergence tests: %u files", vec::len(files)); error!("pp convergence tests: %u files", vec::len(files));
for files.each |file| { for files.each |file| {
if !file_might_not_converge(file) { if !file_might_not_converge(file) {
let s = @result::get(io::read_whole_file_str(file)); let s = @result::get(&io::read_whole_file_str(file));
if !content_might_not_converge(*s) { if !content_might_not_converge(*s) {
error!("pp converge: %s", file.to_str()); error!("pp converge: %s", file.to_str());
// Change from 7u to 2u once // Change from 7u to 2u once
@ -563,7 +563,7 @@ fn check_variants(files: &[Path], cx: context) {
loop; loop;
} }
let s = @result::get(io::read_whole_file_str(file)); let s = @result::get(&io::read_whole_file_str(file));
if contains(*s, ~"#") { if contains(*s, ~"#") {
loop; // Macros are confusing loop; // Macros are confusing
} }

View file

@ -459,7 +459,7 @@ fn test_recv_chan_wrong_task() {
let po = Port(); let po = Port();
let ch = Chan(po); let ch = Chan(po);
send(ch, ~"flower"); send(ch, ~"flower");
assert result::is_err(task::try(|| assert result::is_err(&task::try(||
recv_chan(ch) recv_chan(ch)
)) ))
} }

View file

@ -645,7 +645,7 @@ impl<T: Writer> T : WriterUtil {
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
fn file_writer(path: &Path, flags: ~[FileFlag]) -> Result<Writer, ~str> { fn file_writer(path: &Path, flags: ~[FileFlag]) -> Result<Writer, ~str> {
result::chain(mk_file_writer(path, flags), |w| result::Ok(w)) mk_file_writer(path, flags).chain(|w| result::Ok(w))
} }
@ -864,10 +864,10 @@ mod tests {
{ {
let out: io::Writer = let out: io::Writer =
result::get( result::get(
io::file_writer(tmpfile, ~[io::Create, io::Truncate])); &io::file_writer(tmpfile, ~[io::Create, io::Truncate]));
out.write_str(frood); out.write_str(frood);
} }
let inp: io::Reader = result::get(io::file_reader(tmpfile)); let inp: io::Reader = result::get(&io::file_reader(tmpfile));
let frood2: ~str = inp.read_c_str(); let frood2: ~str = inp.read_c_str();
log(debug, frood2); log(debug, frood2);
assert frood == frood2; assert frood == frood2;

View file

@ -283,7 +283,7 @@ fn test_weaken_task_fail() {
} }
} }
}; };
assert result::is_err(res); assert result::is_err(&res);
} }
/**************************************************************************** /****************************************************************************

View file

@ -1,5 +1,9 @@
//! A type representing either success or failure //! A type representing either success or failure
// NB: transitionary, de-mode-ing.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use cmp::Eq; use cmp::Eq;
use either::Either; use either::Either;
@ -18,8 +22,8 @@ enum Result<T, U> {
* *
* If the result is an error * If the result is an error
*/ */
pure fn get<T: Copy, U>(res: Result<T, U>) -> T { pure fn get<T: Copy, U>(res: &Result<T, U>) -> T {
match res { match *res {
Ok(t) => t, Ok(t) => t,
Err(the_err) => unsafe { Err(the_err) => unsafe {
fail fmt!("get called on error result: %?", the_err) fail fmt!("get called on error result: %?", the_err)
@ -50,23 +54,23 @@ pure fn get_ref<T, U>(res: &a/Result<T, U>) -> &a/T {
* *
* If the result is not an error * If the result is not an error
*/ */
pure fn get_err<T, U: Copy>(res: Result<T, U>) -> U { pure fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
match res { match *res {
Err(u) => u, Err(u) => u,
Ok(_) => fail ~"get_err called on ok result" Ok(_) => fail ~"get_err called on ok result"
} }
} }
/// Returns true if the result is `ok` /// Returns true if the result is `ok`
pure fn is_ok<T, U>(res: Result<T, U>) -> bool { pure fn is_ok<T, U>(res: &Result<T, U>) -> bool {
match res { match *res {
Ok(_) => true, Ok(_) => true,
Err(_) => false Err(_) => false
} }
} }
/// Returns true if the result is `err` /// Returns true if the result is `err`
pure fn is_err<T, U>(res: Result<T, U>) -> bool { pure fn is_err<T, U>(res: &Result<T, U>) -> bool {
!is_ok(res) !is_ok(res)
} }
@ -76,8 +80,8 @@ pure fn is_err<T, U>(res: Result<T, U>) -> bool {
* `ok` result variants are converted to `either::right` variants, `err` * `ok` result variants are converted to `either::right` variants, `err`
* result variants are converted to `either::left`. * result variants are converted to `either::left`.
*/ */
pure fn to_either<T: Copy, U: Copy>(res: Result<U, T>) -> Either<T, U> { pure fn to_either<T: Copy, U: Copy>(res: &Result<U, T>) -> Either<T, U> {
match res { match *res {
Ok(res) => either::Right(res), Ok(res) => either::Right(res),
Err(fail_) => either::Left(fail_) Err(fail_) => either::Left(fail_)
} }
@ -97,11 +101,13 @@ pure fn to_either<T: Copy, U: Copy>(res: Result<U, T>) -> Either<T, U> {
* ok(parse_bytes(buf)) * ok(parse_bytes(buf))
* } * }
*/ */
fn chain<T, U: Copy, V: Copy>(res: Result<T, V>, op: fn(T) -> Result<U, V>) fn chain<T, U: Copy, V: Copy>(+res: Result<T, V>, op: fn(+t: T) -> Result<U, V>)
-> Result<U, V> { -> Result<U, V> {
match res { // XXX: Should be writable with move + match
Ok(t) => op(t), if res.is_ok() {
Err(e) => Err(e) op(unwrap(res))
} else {
Err(unwrap_err(res))
} }
} }
@ -114,10 +120,10 @@ fn chain<T, U: Copy, V: Copy>(res: Result<T, V>, op: fn(T) -> Result<U, V>)
* successful result while handling an error. * successful result while handling an error.
*/ */
fn chain_err<T: Copy, U: Copy, V: Copy>( fn chain_err<T: Copy, U: Copy, V: Copy>(
res: Result<T, V>, +res: Result<T, V>,
op: fn(V) -> Result<T, U>) op: fn(+t: V) -> Result<T, U>)
-> Result<T, U> { -> Result<T, U> {
match res { move match res {
Ok(t) => Ok(t), Ok(t) => Ok(t),
Err(v) => op(v) Err(v) => op(v)
} }
@ -137,9 +143,9 @@ fn chain_err<T: Copy, U: Copy, V: Copy>(
* print_buf(buf) * print_buf(buf)
* } * }
*/ */
fn iter<T, E>(res: Result<T, E>, f: fn(T)) { fn iter<T, E>(res: &Result<T, E>, f: fn((&T))) {
match res { match *res {
Ok(t) => f(t), Ok(t) => f(&t),
Err(_) => () Err(_) => ()
} }
} }
@ -152,10 +158,10 @@ fn iter<T, E>(res: Result<T, E>, f: fn(T)) {
* This function can be used to pass through a successful result while * This function can be used to pass through a successful result while
* handling an error. * handling an error.
*/ */
fn iter_err<T, E>(res: Result<T, E>, f: fn(E)) { fn iter_err<T, E>(res: &Result<T, E>, f: fn((&E))) {
match res { match *res {
Ok(_) => (), Ok(_) => (),
Err(e) => f(e) Err(e) => f(&e)
} }
} }
@ -173,10 +179,10 @@ fn iter_err<T, E>(res: Result<T, E>, f: fn(E)) {
* parse_bytes(buf) * parse_bytes(buf)
* } * }
*/ */
fn map<T, E: Copy, U: Copy>(res: Result<T, E>, op: fn(T) -> U) fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: fn((&T)) -> U)
-> Result<U, E> { -> Result<U, E> {
match res { match *res {
Ok(t) => Ok(op(t)), Ok(t) => Ok(op(&t)),
Err(e) => Err(e) Err(e) => Err(e)
} }
} }
@ -189,63 +195,65 @@ fn map<T, E: Copy, U: Copy>(res: Result<T, E>, op: fn(T) -> U)
* is immediately returned. This function can be used to pass through a * is immediately returned. This function can be used to pass through a
* successful result while handling an error. * successful result while handling an error.
*/ */
fn map_err<T: Copy, E, F: Copy>(res: Result<T, E>, op: fn(E) -> F) fn map_err<T: Copy, E, F: Copy>(res: &Result<T, E>, op: fn((&E)) -> F)
-> Result<T, F> { -> Result<T, F> {
match res { match *res {
Ok(t) => Ok(t), Ok(t) => Ok(t),
Err(e) => Err(op(e)) Err(e) => Err(op(&e))
} }
} }
impl<T, E> Result<T, E> { impl<T, E> Result<T, E> {
fn is_ok() -> bool { is_ok(self) } fn is_ok() -> bool { is_ok(&self) }
fn is_err() -> bool { is_err(self) } fn is_err() -> bool { is_err(&self) }
fn iter(f: fn(T)) { fn iter(f: fn((&T))) {
match self { match self {
Ok(t) => f(t), Ok(t) => f(&t),
Err(_) => () Err(_) => ()
} }
} }
fn iter_err(f: fn(E)) { fn iter_err(f: fn((&E))) {
match self { match self {
Ok(_) => (), Ok(_) => (),
Err(e) => f(e) Err(e) => f(&e)
} }
} }
} }
impl<T: Copy, E> Result<T, E> { impl<T: Copy, E> Result<T, E> {
fn get() -> T { get(self) } fn get() -> T { get(&self) }
fn map_err<F:Copy>(op: fn(E) -> F) -> Result<T,F> { fn map_err<F:Copy>(op: fn((&E)) -> F) -> Result<T,F> {
match self { match self {
Ok(t) => Ok(t), Ok(t) => Ok(t),
Err(e) => Err(op(e)) Err(e) => Err(op(&e))
} }
} }
} }
impl<T, E: Copy> Result<T, E> { impl<T, E: Copy> Result<T, E> {
fn get_err() -> E { get_err(self) } fn get_err() -> E { get_err(&self) }
fn map<U:Copy>(op: fn(T) -> U) -> Result<U,E> { fn map<U:Copy>(op: fn((&T)) -> U) -> Result<U,E> {
match self { match self {
Ok(t) => Ok(op(t)), Ok(t) => Ok(op(&t)),
Err(e) => Err(e) Err(e) => Err(e)
} }
} }
} }
impl<T: Copy, E: Copy> Result<T, E> { impl<T: Copy, E: Copy> Result<T, E> {
fn chain<U:Copy>(op: fn(T) -> Result<U,E>) -> Result<U,E> { fn chain<U:Copy>(op: fn(+t: T) -> Result<U,E>) -> Result<U,E> {
chain(self, op) // XXX: Bad copy
chain(copy self, op)
} }
fn chain_err<F:Copy>(op: fn(E) -> Result<T,F>) -> Result<T,F> { fn chain_err<F:Copy>(op: fn(+t: E) -> Result<T,F>) -> Result<T,F> {
chain_err(self, op) // XXX: Bad copy
chain_err(copy self, op)
} }
} }
@ -280,11 +288,11 @@ fn map_vec<T,U:Copy,V:Copy>(
} }
fn map_opt<T,U:Copy,V:Copy>( fn map_opt<T,U:Copy,V:Copy>(
o_t: Option<T>, op: fn(T) -> Result<V,U>) -> Result<Option<V>,U> { o_t: &Option<T>, op: fn((&T)) -> Result<V,U>) -> Result<Option<V>,U> {
match o_t { match *o_t {
None => Ok(None), None => Ok(None),
Some(t) => match op(t) { Some(t) => match op(&t) {
Ok(v) => Ok(Some(v)), Ok(v) => Ok(Some(v)),
Err(e) => Err(e) Err(e) => Err(e)
} }
@ -301,14 +309,14 @@ fn map_opt<T,U:Copy,V:Copy>(
* to accommodate an error like the vectors being of different lengths. * to accommodate an error like the vectors being of different lengths.
*/ */
fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T], fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
op: fn(S,T) -> Result<V,U>) -> Result<~[V],U> { op: fn((&S),(&T)) -> Result<V,U>) -> Result<~[V],U> {
assert vec::same_length(ss, ts); assert vec::same_length(ss, ts);
let n = vec::len(ts); let n = vec::len(ts);
let mut vs = vec::with_capacity(n); let mut vs = vec::with_capacity(n);
let mut i = 0u; let mut i = 0u;
while i < n { while i < n {
match op(ss[i],ts[i]) { match op(&ss[i],&ts[i]) {
Ok(v) => vec::push(vs, v), Ok(v) => vec::push(vs, v),
Err(u) => return Err(u) Err(u) => return Err(u)
} }
@ -323,13 +331,13 @@ fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
* on its own as no result vector is built. * on its own as no result vector is built.
*/ */
fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T], fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
op: fn(S,T) -> Result<(),U>) -> Result<(),U> { op: fn((&S),(&T)) -> Result<(),U>) -> Result<(),U> {
assert vec::same_length(ss, ts); assert vec::same_length(ss, ts);
let n = vec::len(ts); let n = vec::len(ts);
let mut i = 0u; let mut i = 0u;
while i < n { while i < n {
match op(ss[i],ts[i]) { match op(&ss[i],&ts[i]) {
Ok(()) => (), Ok(()) => (),
Err(u) => return Err(u) Err(u) => return Err(u)
} }
@ -380,7 +388,7 @@ mod tests {
#[legacy_exports]; #[legacy_exports];
fn op1() -> result::Result<int, ~str> { result::Ok(666) } fn op1() -> result::Result<int, ~str> { result::Ok(666) }
fn op2(&&i: int) -> result::Result<uint, ~str> { fn op2(+i: int) -> result::Result<uint, ~str> {
result::Ok(i as uint + 1u) result::Ok(i as uint + 1u)
} }
@ -388,12 +396,12 @@ mod tests {
#[test] #[test]
fn chain_success() { fn chain_success() {
assert get(chain(op1(), op2)) == 667u; assert get(&chain(op1(), op2)) == 667u;
} }
#[test] #[test]
fn chain_failure() { fn chain_failure() {
assert get_err(chain(op3(), op2)) == ~"sadface"; assert get_err(&chain(op3(), op2)) == ~"sadface";
} }
#[test] #[test]

View file

@ -892,7 +892,7 @@ mod tests {
])) ]))
]); ]);
let astr = to_str(a); let astr = to_str(a);
let b = result::get(from_str(astr)); let b = result::get(&from_str(astr));
let bstr = to_str(b); let bstr = to_str(b);
assert astr == bstr; assert astr == bstr;
assert a == b; assert a == b;
@ -1040,24 +1040,24 @@ mod tests {
assert from_str(~"{\"a\":1,") == assert from_str(~"{\"a\":1,") ==
Err({line: 1u, col: 8u, msg: @~"EOF while parsing object"}); Err({line: 1u, col: 8u, msg: @~"EOF while parsing object"});
assert eq(result::get(from_str(~"{}")), mk_dict(~[])); assert eq(result::get(&from_str(~"{}")), mk_dict(~[]));
assert eq(result::get(from_str(~"{\"a\": 3}")), assert eq(result::get(&from_str(~"{\"a\": 3}")),
mk_dict(~[(~"a", Num(3.0f))])); mk_dict(~[(~"a", Num(3.0f))]));
assert eq(result::get(from_str(~"{ \"a\": null, \"b\" : true }")), assert eq(result::get(&from_str(~"{ \"a\": null, \"b\" : true }")),
mk_dict(~[ mk_dict(~[
(~"a", Null), (~"a", Null),
(~"b", Boolean(true))])); (~"b", Boolean(true))]));
assert eq(result::get(from_str(~"\n{ \"a\": null, \"b\" : true }\n")), assert eq(result::get(&from_str(~"\n{ \"a\": null, \"b\" : true }\n")),
mk_dict(~[ mk_dict(~[
(~"a", Null), (~"a", Null),
(~"b", Boolean(true))])); (~"b", Boolean(true))]));
assert eq(result::get(from_str(~"{\"a\" : 1.0 ,\"b\": [ true ]}")), assert eq(result::get(&from_str(~"{\"a\" : 1.0 ,\"b\": [ true ]}")),
mk_dict(~[ mk_dict(~[
(~"a", Num(1.0)), (~"a", Num(1.0)),
(~"b", List(@~[Boolean(true)])) (~"b", List(@~[Boolean(true)]))
])); ]));
assert eq(result::get(from_str( assert eq(result::get(&from_str(
~"{" + ~"{" +
~"\"a\": 1.0, " + ~"\"a\": 1.0, " +
~"\"b\": [" + ~"\"b\": [" +

View file

@ -176,24 +176,24 @@ mod v4 {
unsafe { unsafe {
let INADDR_NONE = ll::get_INADDR_NONE(); let INADDR_NONE = ll::get_INADDR_NONE();
let ip_rep_result = parse_to_ipv4_rep(ip); let ip_rep_result = parse_to_ipv4_rep(ip);
if result::is_err(ip_rep_result) { if result::is_err(&ip_rep_result) {
let err_str = result::get_err(ip_rep_result); let err_str = result::get_err(&ip_rep_result);
return result::Err({err_msg: err_str}) return result::Err({err_msg: err_str})
} }
// ipv4_rep.as_u32 is unsafe :/ // ipv4_rep.as_u32 is unsafe :/
let input_is_inaddr_none = let input_is_inaddr_none =
result::get(ip_rep_result).as_u32() == INADDR_NONE; result::get(&ip_rep_result).as_u32() == INADDR_NONE;
let new_addr = uv_ip4_addr(str::from_slice(ip), 22); let new_addr = uv_ip4_addr(str::from_slice(ip), 22);
let reformatted_name = uv_ip4_name(&new_addr); let reformatted_name = uv_ip4_name(&new_addr);
log(debug, fmt!("try_parse_addr: input ip: %s reparsed ip: %s", log(debug, fmt!("try_parse_addr: input ip: %s reparsed ip: %s",
ip, reformatted_name)); ip, reformatted_name));
let ref_ip_rep_result = parse_to_ipv4_rep(reformatted_name); let ref_ip_rep_result = parse_to_ipv4_rep(reformatted_name);
if result::is_err(ref_ip_rep_result) { if result::is_err(&ref_ip_rep_result) {
let err_str = result::get_err(ref_ip_rep_result); let err_str = result::get_err(&ref_ip_rep_result);
return result::Err({err_msg: err_str}) return result::Err({err_msg: err_str})
} }
if result::get(ref_ip_rep_result).as_u32() == INADDR_NONE && if result::get(&ref_ip_rep_result).as_u32() == INADDR_NONE &&
!input_is_inaddr_none { !input_is_inaddr_none {
return result::Err( return result::Err(
{err_msg: ~"uv_ip4_name produced invalid result."}) {err_msg: ~"uv_ip4_name produced invalid result."})
@ -358,7 +358,7 @@ mod test {
let localhost_name = ~"localhost"; let localhost_name = ~"localhost";
let iotask = uv::global_loop::get(); let iotask = uv::global_loop::get();
let ga_result = get_addr(localhost_name, iotask); let ga_result = get_addr(localhost_name, iotask);
if result::is_err(ga_result) { if result::is_err(&ga_result) {
fail ~"got err result from net::ip::get_addr();" fail ~"got err result from net::ip::get_addr();"
} }
// note really sure how to realiably test/assert // note really sure how to realiably test/assert
@ -384,6 +384,6 @@ mod test {
let localhost_name = ~"sjkl234m,./sdf"; let localhost_name = ~"sjkl234m,./sdf";
let iotask = uv::global_loop::get(); let iotask = uv::global_loop::get();
let ga_result = get_addr(localhost_name, iotask); let ga_result = get_addr(localhost_name, iotask);
assert result::is_err(ga_result); assert result::is_err(&ga_result);
} }
} }

View file

@ -871,17 +871,17 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint)
log(debug, ~"starting tcp::read"); log(debug, ~"starting tcp::read");
let iotask = (*socket_data).iotask; let iotask = (*socket_data).iotask;
let rs_result = read_start_common_impl(socket_data); let rs_result = read_start_common_impl(socket_data);
if result::is_err(rs_result) { if result::is_err(&rs_result) {
let err_data = result::get_err(rs_result); let err_data = result::get_err(&rs_result);
result::Err(err_data) result::Err(err_data)
} }
else { else {
log(debug, ~"tcp::read before recv_timeout"); log(debug, ~"tcp::read before recv_timeout");
let read_result = if timeout_msecs > 0u { let read_result = if timeout_msecs > 0u {
timer::recv_timeout( timer::recv_timeout(
iotask, timeout_msecs, result::get(rs_result)) iotask, timeout_msecs, result::get(&rs_result))
} else { } else {
Some(core::comm::recv(result::get(rs_result))) Some(core::comm::recv(result::get(&rs_result)))
}; };
log(debug, ~"tcp::read after recv_timeout"); log(debug, ~"tcp::read after recv_timeout");
match read_result { match read_result {
@ -1514,9 +1514,9 @@ mod test {
let accept_result = accept(new_conn); let accept_result = accept(new_conn);
log(debug, ~"SERVER: after accept()"); log(debug, ~"SERVER: after accept()");
if result::is_err(accept_result) { if result::is_err(&accept_result) {
log(debug, ~"SERVER: error accept connection"); log(debug, ~"SERVER: error accept connection");
let err_data = result::get_err(accept_result); let err_data = result::get_err(&accept_result);
core::comm::send(kill_ch, Some(err_data)); core::comm::send(kill_ch, Some(err_data));
log(debug, log(debug,
~"SERVER/WORKER: send on err cont ch"); ~"SERVER/WORKER: send on err cont ch");
@ -1558,8 +1558,8 @@ mod test {
log(debug, ~"SERVER: recv'd on cont_ch..leaving listen cb"); log(debug, ~"SERVER: recv'd on cont_ch..leaving listen cb");
}); });
// err check on listen_result // err check on listen_result
if result::is_err(listen_result) { if result::is_err(&listen_result) {
match result::get_err(listen_result) { match result::get_err(&listen_result) {
GenericListenErr(name, msg) => { GenericListenErr(name, msg) => {
fail fmt!("SERVER: exited abnormally name %s msg %s", fail fmt!("SERVER: exited abnormally name %s msg %s",
name, msg); name, msg);
@ -1592,8 +1592,8 @@ mod test {
new_conn, kill_ch); new_conn, kill_ch);
}); });
// err check on listen_result // err check on listen_result
if result::is_err(listen_result) { if result::is_err(&listen_result) {
result::get_err(listen_result) result::get_err(&listen_result)
} }
else { else {
fail ~"SERVER: did not fail as expected" fail ~"SERVER: did not fail as expected"
@ -1609,9 +1609,9 @@ mod test {
log(debug, ~"CLIENT: starting.."); log(debug, ~"CLIENT: starting..");
let connect_result = connect(move server_ip_addr, server_port, let connect_result = connect(move server_ip_addr, server_port,
iotask); iotask);
if result::is_err(connect_result) { if result::is_err(&connect_result) {
log(debug, ~"CLIENT: failed to connect"); log(debug, ~"CLIENT: failed to connect");
let err_data = result::get_err(connect_result); let err_data = result::get_err(&connect_result);
Err(err_data) Err(err_data)
} }
else { else {
@ -1636,9 +1636,9 @@ mod test {
fn tcp_write_single(sock: &TcpSocket, val: ~[u8]) { fn tcp_write_single(sock: &TcpSocket, val: ~[u8]) {
let write_result_future = sock.write_future(val); let write_result_future = sock.write_future(val);
let write_result = write_result_future.get(); let write_result = write_result_future.get();
if result::is_err(write_result) { if result::is_err(&write_result) {
log(debug, ~"tcp_write_single: write failed!"); log(debug, ~"tcp_write_single: write failed!");
let err_data = result::get_err(write_result); let err_data = result::get_err(&write_result);
log(debug, fmt!("tcp_write_single err name: %s msg: %s", log(debug, fmt!("tcp_write_single err name: %s msg: %s",
err_data.err_name, err_data.err_msg)); err_data.err_name, err_data.err_msg));
// meh. torn on what to do here. // meh. torn on what to do here.

View file

@ -627,30 +627,30 @@ fn get_query_fragment(rawurl: &str) ->
fn from_str(rawurl: &str) -> result::Result<Url, ~str> { fn from_str(rawurl: &str) -> result::Result<Url, ~str> {
// scheme // scheme
let mut schm = get_scheme(rawurl); let mut schm = get_scheme(rawurl);
if result::is_err(schm) { if result::is_err(&schm) {
return result::Err(copy *result::get_err(schm)); return result::Err(copy *result::get_err(&schm));
} }
let (scheme, rest) = result::unwrap(schm); let (scheme, rest) = result::unwrap(schm);
// authority // authority
let mut auth = get_authority(rest); let mut auth = get_authority(rest);
if result::is_err(auth) { if result::is_err(&auth) {
return result::Err(copy *result::get_err(auth)); return result::Err(copy *result::get_err(&auth));
} }
let (userinfo, host, port, rest) = result::unwrap(auth); let (userinfo, host, port, rest) = result::unwrap(auth);
// path // path
let has_authority = if host == ~"" { false } else { true }; let has_authority = if host == ~"" { false } else { true };
let mut pth = get_path(rest, has_authority); let mut pth = get_path(rest, has_authority);
if result::is_err(pth) { if result::is_err(&pth) {
return result::Err(copy *result::get_err(pth)); return result::Err(copy *result::get_err(&pth));
} }
let (path, rest) = result::unwrap(pth); let (path, rest) = result::unwrap(pth);
// query and fragment // query and fragment
let mut qry = get_query_fragment(rest); let mut qry = get_query_fragment(rest);
if result::is_err(qry) { if result::is_err(&qry) {
return result::Err(copy *result::get_err(qry)); return result::Err(copy *result::get_err(&qry));
} }
let (query, fragment) = result::unwrap(qry); let (query, fragment) = result::unwrap(qry);
@ -796,13 +796,13 @@ mod tests {
assert p == option::Some(~"8000"); assert p == option::Some(~"8000");
// invalid authorities; // invalid authorities;
assert result::is_err(get_authority( assert result::is_err(&get_authority(
~"//user:pass@rust-lang:something")); ~"//user:pass@rust-lang:something"));
assert result::is_err(get_authority( assert result::is_err(&get_authority(
~"//user@rust-lang:something:/path")); ~"//user@rust-lang:something:/path"));
assert result::is_err(get_authority( assert result::is_err(&get_authority(
~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:800a")); ~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:800a"));
assert result::is_err(get_authority( assert result::is_err(&get_authority(
~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00")); ~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00"));
// these parse as empty, because they don't start with '//' // these parse as empty, because they don't start with '//'
@ -830,7 +830,7 @@ mod tests {
assert r == ~"?q=v"; assert r == ~"?q=v";
//failure cases //failure cases
assert result::is_err(get_path(~"something?q", true)); assert result::is_err(&get_path(~"something?q", true));
} }
@ -877,13 +877,13 @@ mod tests {
#[test] #[test]
fn test_no_scheme() { fn test_no_scheme() {
assert result::is_err(get_scheme(~"noschemehere.html")); assert result::is_err(&get_scheme(~"noschemehere.html"));
} }
#[test] #[test]
fn test_invalid_scheme_errors() { fn test_invalid_scheme_errors() {
assert result::is_err(from_str(~"99://something")); assert result::is_err(&from_str(~"99://something"));
assert result::is_err(from_str(~"://something")); assert result::is_err(&from_str(~"://something"));
} }
#[test] #[test]

View file

@ -415,7 +415,7 @@ fn ty_of_arg<AC: ast_conv, RS: region_scope Copy Owned>(
let mode = { let mode = {
match a.mode { match a.mode {
ast::infer(_) if expected_ty.is_some() => { ast::infer(_) if expected_ty.is_some() => {
result::get(ty::unify_mode( result::get(&ty::unify_mode(
self.tcx(), self.tcx(),
ty::expected_found {expected: expected_ty.get().mode, ty::expected_found {expected: expected_ty.get().mode,
found: a.mode})) found: a.mode}))
@ -434,7 +434,7 @@ fn ty_of_arg<AC: ast_conv, RS: region_scope Copy Owned>(
_ => { _ => {
let m1 = ast::expl(ty::default_arg_mode_for_ty(self.tcx(), let m1 = ast::expl(ty::default_arg_mode_for_ty(self.tcx(),
ty)); ty));
result::get(ty::unify_mode( result::get(&ty::unify_mode(
self.tcx(), self.tcx(),
ty::expected_found {expected: m1, ty::expected_found {expected: m1,
found: a.mode})) found: a.mode}))

View file

@ -221,7 +221,7 @@ fn super_tps<C:combine>(
if vec::same_length(as_, bs) { if vec::same_length(as_, bs) {
iter_vec2(as_, bs, |a, b| { iter_vec2(as_, bs, |a, b| {
eq_tys(self, a, b) eq_tys(self, *a, *b)
}).then(|| Ok(as_.to_vec()) ) }).then(|| Ok(as_.to_vec()) )
} else { } else {
Err(ty::terr_ty_param_size( Err(ty::terr_ty_param_size(
@ -327,7 +327,7 @@ fn super_fn_sigs<C:combine>(
b_args: ~[ty::arg]) -> cres<~[ty::arg]> { b_args: ~[ty::arg]) -> cres<~[ty::arg]> {
if vec::same_length(a_args, b_args) { if vec::same_length(a_args, b_args) {
map_vec2(a_args, b_args, |a, b| self.args(a, b)) map_vec2(a_args, b_args, |a, b| self.args(*a, *b))
} else { } else {
Err(ty::terr_arg_count) Err(ty::terr_arg_count)
} }
@ -474,7 +474,7 @@ fn super_tys<C:combine>(
(ty::ty_rec(as_), ty::ty_rec(bs)) => { (ty::ty_rec(as_), ty::ty_rec(bs)) => {
if vec::same_length(as_, bs) { if vec::same_length(as_, bs) {
map_vec2(as_, bs, |a,b| { map_vec2(as_, bs, |a,b| {
self.flds(a, b) self.flds(*a, *b)
}).chain(|flds| Ok(ty::mk_rec(tcx, flds)) ) }).chain(|flds| Ok(ty::mk_rec(tcx, flds)) )
} else { } else {
Err(ty::terr_record_size(expected_found(self, as_.len(), Err(ty::terr_record_size(expected_found(self, as_.len(),
@ -484,7 +484,7 @@ fn super_tys<C:combine>(
(ty::ty_tup(as_), ty::ty_tup(bs)) => { (ty::ty_tup(as_), ty::ty_tup(bs)) => {
if vec::same_length(as_, bs) { if vec::same_length(as_, bs) {
map_vec2(as_, bs, |a, b| self.tys(a, b) ) map_vec2(as_, bs, |a, b| self.tys(*a, *b) )
.chain(|ts| Ok(ty::mk_tup(tcx, ts)) ) .chain(|ts| Ok(ty::mk_tup(tcx, ts)) )
} else { } else {
Err(ty::terr_tuple_size( Err(ty::terr_tuple_size(

View file

@ -285,20 +285,20 @@ mod test {
#[test] #[test]
fn should_error_with_no_crates() { fn should_error_with_no_crates() {
let config = test::parse_config(~[~"rustdoc"]); let config = test::parse_config(~[~"rustdoc"]);
assert result::get_err(config) == ~"no crates specified"; assert config.get_err() == ~"no crates specified";
} }
#[test] #[test]
fn should_error_with_multiple_crates() { fn should_error_with_multiple_crates() {
let config = let config =
test::parse_config(~[~"rustdoc", ~"crate1.rc", ~"crate2.rc"]); test::parse_config(~[~"rustdoc", ~"crate1.rc", ~"crate2.rc"]);
assert result::get_err(config) == ~"multiple crates specified"; assert config.get_err() == ~"multiple crates specified";
} }
#[test] #[test]
fn should_set_output_dir_to_cwd_if_not_provided() { fn should_set_output_dir_to_cwd_if_not_provided() {
let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]);
assert result::get(config).output_dir == Path("."); assert config.get().output_dir == Path(".");
} }
#[test] #[test]
@ -306,13 +306,13 @@ fn should_set_output_dir_if_provided() {
let config = test::parse_config(~[ let config = test::parse_config(~[
~"rustdoc", ~"crate.rc", ~"--output-dir", ~"snuggles" ~"rustdoc", ~"crate.rc", ~"--output-dir", ~"snuggles"
]); ]);
assert result::get(config).output_dir == Path("snuggles"); assert config.get().output_dir == Path("snuggles");
} }
#[test] #[test]
fn should_set_output_format_to_pandoc_html_if_not_provided() { fn should_set_output_format_to_pandoc_html_if_not_provided() {
let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]);
assert result::get(config).output_format == PandocHtml; assert config.get().output_format == PandocHtml;
} }
#[test] #[test]
@ -320,7 +320,7 @@ fn should_set_output_format_to_markdown_if_requested() {
let config = test::parse_config(~[ let config = test::parse_config(~[
~"rustdoc", ~"crate.rc", ~"--output-format", ~"markdown" ~"rustdoc", ~"crate.rc", ~"--output-format", ~"markdown"
]); ]);
assert result::get(config).output_format == Markdown; assert config.get().output_format == Markdown;
} }
#[test] #[test]
@ -328,7 +328,7 @@ fn should_set_output_format_to_pandoc_html_if_requested() {
let config = test::parse_config(~[ let config = test::parse_config(~[
~"rustdoc", ~"crate.rc", ~"--output-format", ~"html" ~"rustdoc", ~"crate.rc", ~"--output-format", ~"html"
]); ]);
assert result::get(config).output_format == PandocHtml; assert config.get().output_format == PandocHtml;
} }
#[test] #[test]
@ -336,13 +336,13 @@ fn should_error_on_bogus_format() {
let config = test::parse_config(~[ let config = test::parse_config(~[
~"rustdoc", ~"crate.rc", ~"--output-format", ~"bogus" ~"rustdoc", ~"crate.rc", ~"--output-format", ~"bogus"
]); ]);
assert result::get_err(config) == ~"unknown output format 'bogus'"; assert config.get_err() == ~"unknown output format 'bogus'";
} }
#[test] #[test]
fn should_set_output_style_to_doc_per_mod_by_default() { fn should_set_output_style_to_doc_per_mod_by_default() {
let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]);
assert result::get(config).output_style == DocPerMod; assert config.get().output_style == DocPerMod;
} }
#[test] #[test]
@ -350,7 +350,7 @@ fn should_set_output_style_to_one_doc_if_requested() {
let config = test::parse_config(~[ let config = test::parse_config(~[
~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-crate" ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-crate"
]); ]);
assert result::get(config).output_style == DocPerCrate; assert config.get().output_style == DocPerCrate;
} }
#[test] #[test]
@ -358,7 +358,7 @@ fn should_set_output_style_to_doc_per_mod_if_requested() {
let config = test::parse_config(~[ let config = test::parse_config(~[
~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-mod" ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-mod"
]); ]);
assert result::get(config).output_style == DocPerMod; assert config.get().output_style == DocPerMod;
} }
#[test] #[test]
@ -366,7 +366,7 @@ fn should_error_on_bogus_output_style() {
let config = test::parse_config(~[ let config = test::parse_config(~[
~"rustdoc", ~"crate.rc", ~"--output-style", ~"bogus" ~"rustdoc", ~"crate.rc", ~"--output-style", ~"bogus"
]); ]);
assert result::get_err(config) == ~"unknown output style 'bogus'"; assert config.get_err() == ~"unknown output style 'bogus'";
} }
#[test] #[test]
@ -374,11 +374,11 @@ fn should_set_pandoc_command_if_requested() {
let config = test::parse_config(~[ let config = test::parse_config(~[
~"rustdoc", ~"crate.rc", ~"--pandoc-cmd", ~"panda-bear-doc" ~"rustdoc", ~"crate.rc", ~"--pandoc-cmd", ~"panda-bear-doc"
]); ]);
assert result::get(config).pandoc_cmd == Some(~"panda-bear-doc"); assert config.get().pandoc_cmd == Some(~"panda-bear-doc");
} }
#[test] #[test]
fn should_set_pandoc_command_when_using_pandoc() { fn should_set_pandoc_command_when_using_pandoc() {
let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]);
assert result::get(config).pandoc_cmd == Some(~"pandoc"); assert config.get().pandoc_cmd == Some(~"pandoc");
} }

View file

@ -56,7 +56,7 @@ fn read_line() {
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data")); .push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
for int::range(0, 3) |_i| { for int::range(0, 3) |_i| {
let reader = result::get(io::file_reader(&path)); let reader = result::get(&io::file_reader(&path));
while !reader.eof() { while !reader.eof() {
reader.read_line(); reader.read_line();
} }

View file

@ -81,7 +81,7 @@ fn main(++args: ~[~str]) {
}; };
let writer = if os::getenv(~"RUST_BENCH").is_some() { let writer = if os::getenv(~"RUST_BENCH").is_some() {
result::get(io::file_writer(&Path("./shootout-fasta.data"), result::get(&io::file_writer(&Path("./shootout-fasta.data"),
~[io::Truncate, io::Create])) ~[io::Truncate, io::Create]))
} else { } else {
io::stdout() io::stdout()

View file

@ -134,7 +134,7 @@ fn main(++args: ~[~str]) {
// get to this massive data set, but #include_bin chokes on it (#2598) // get to this massive data set, but #include_bin chokes on it (#2598)
let path = Path(env!("CFG_SRC_DIR")) let path = Path(env!("CFG_SRC_DIR"))
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data")); .push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
result::get(io::file_reader(&path)) result::get(&io::file_reader(&path))
} else { } else {
io::stdin() io::stdin()
}; };

View file

@ -131,7 +131,7 @@ fn main(++args: ~[~str]) {
// get to this massive data set, but #include_bin chokes on it (#2598) // get to this massive data set, but #include_bin chokes on it (#2598)
let path = Path(env!("CFG_SRC_DIR")) let path = Path(env!("CFG_SRC_DIR"))
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data")); .push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
result::get(io::file_reader(&path)) result::get(&io::file_reader(&path))
} else { } else {
io::stdin() io::stdin()
}; };

View file

@ -114,7 +114,7 @@ fn writer(path: ~str, writech: comm::Chan<comm::Chan<line>>, size: uint)
} }
_ => { _ => {
result::get( result::get(
io::file_writer(&Path(path), &io::file_writer(&Path(path),
~[io::Create, io::Truncate])) ~[io::Create, io::Truncate]))
} }
}; };

View file

@ -1,4 +1,4 @@
// error-pattern:get called on error result: ~"kitty" // error-pattern:get called on error result: ~"kitty"
fn main() { fn main() {
log(error, result::get(result::Err::<int,~str>(~"kitty"))); log(error, result::get(&result::Err::<int,~str>(~"kitty")));
} }

View file

@ -2,7 +2,7 @@
fn adder(+x: @int, +y: @int) -> int { return *x + *y; } fn adder(+x: @int, +y: @int) -> int { return *x + *y; }
fn failer() -> @int { fail; } fn failer() -> @int { fail; }
fn main() { fn main() {
assert(result::is_err(task::try(|| { assert(result::is_err(&task::try(|| {
adder(@2, failer()); () adder(@2, failer()); ()
}))); })));
} }