Demode core::result
This commit is contained in:
parent
62649f0412
commit
d05e2ad66c
@ -460,7 +460,7 @@ fn parse_source(name: ~str, j: json::Json) -> source {
|
||||
fn try_parse_sources(filename: &Path, sources: map::HashMap<~str, source>) {
|
||||
if !os::path_exists(filename) { return; }
|
||||
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)) => {
|
||||
for j.each |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");
|
||||
if !os::path_exists(&srcfile) { return; }
|
||||
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)) => {
|
||||
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");
|
||||
if !os::path_exists(&pkgfile) { return; }
|
||||
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)) => {
|
||||
for (*js).each |j| {
|
||||
match *j {
|
||||
@ -659,7 +659,7 @@ fn build_cargo_options(argv: ~[~str]) -> options {
|
||||
fn configure(opts: options) -> cargo {
|
||||
let home = match get_cargo_root() {
|
||||
Ok(home) => home,
|
||||
Err(_err) => result::get(get_cargo_sysroot())
|
||||
Err(_err) => get_cargo_sysroot().get()
|
||||
};
|
||||
|
||||
let get_cargo_dir = match opts.mode {
|
||||
@ -668,7 +668,7 @@ fn configure(opts: options) -> cargo {
|
||||
local_mode => get_cargo_root_nearest
|
||||
};
|
||||
|
||||
let p = result::get(get_cargo_dir());
|
||||
let p = get_cargo_dir().get();
|
||||
|
||||
let sources = map::HashMap();
|
||||
try_parse_sources(&home.push("sources.json"), sources);
|
||||
|
@ -9,7 +9,7 @@ type expected_error = { line: uint, kind: ~str, msg: ~str };
|
||||
// Load any test directives embedded in the file
|
||||
fn load_errors(testfile: &Path) -> ~[expected_error] {
|
||||
let mut error_patterns = ~[];
|
||||
let rdr = result::get(io::file_reader(testfile));
|
||||
let rdr = io::file_reader(testfile).get();
|
||||
let mut line_num = 1u;
|
||||
while !rdr.eof() {
|
||||
let ln = rdr.read_line();
|
||||
|
@ -73,7 +73,7 @@ fn is_test_ignored(config: config, testfile: &Path) -> 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() {
|
||||
let ln = rdr.read_line();
|
||||
|
||||
|
@ -109,7 +109,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) {
|
||||
let rounds =
|
||||
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;
|
||||
while round < rounds {
|
||||
@ -129,7 +129,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: &Path) {
|
||||
match props.pp_exact {
|
||||
option::Some(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] }
|
||||
};
|
||||
@ -561,8 +561,8 @@ fn dump_output(config: config, testfile: &Path, out: ~str, err: ~str) {
|
||||
fn dump_output_file(config: config, testfile: &Path,
|
||||
out: ~str, extension: ~str) {
|
||||
let outfile = make_out_name(config, testfile, extension);
|
||||
let writer = result::get(
|
||||
io::file_writer(&outfile, ~[io::Create, io::Truncate]));
|
||||
let writer =
|
||||
io::file_writer(&outfile, ~[io::Create, io::Truncate]).get();
|
||||
writer.write_str(out);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ impl test_mode : cmp::Eq {
|
||||
|
||||
fn write_file(filename: &Path, content: ~str) {
|
||||
result::get(
|
||||
io::file_writer(filename, ~[io::Create, io::Truncate]))
|
||||
&io::file_writer(filename, ~[io::Create, io::Truncate]))
|
||||
.write_str(content);
|
||||
}
|
||||
|
||||
@ -543,7 +543,7 @@ fn check_convergence(files: &[Path]) {
|
||||
error!("pp convergence tests: %u files", vec::len(files));
|
||||
for files.each |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) {
|
||||
error!("pp converge: %s", file.to_str());
|
||||
// Change from 7u to 2u once
|
||||
@ -563,7 +563,7 @@ fn check_variants(files: &[Path], cx: context) {
|
||||
loop;
|
||||
}
|
||||
|
||||
let s = @result::get(io::read_whole_file_str(file));
|
||||
let s = @result::get(&io::read_whole_file_str(file));
|
||||
if contains(*s, ~"#") {
|
||||
loop; // Macros are confusing
|
||||
}
|
||||
|
@ -459,7 +459,7 @@ fn test_recv_chan_wrong_task() {
|
||||
let po = Port();
|
||||
let ch = Chan(po);
|
||||
send(ch, ~"flower");
|
||||
assert result::is_err(task::try(||
|
||||
assert result::is_err(&task::try(||
|
||||
recv_chan(ch)
|
||||
))
|
||||
}
|
||||
|
@ -645,7 +645,7 @@ impl<T: Writer> T : WriterUtil {
|
||||
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
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 =
|
||||
result::get(
|
||||
io::file_writer(tmpfile, ~[io::Create, io::Truncate]));
|
||||
&io::file_writer(tmpfile, ~[io::Create, io::Truncate]));
|
||||
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();
|
||||
log(debug, frood2);
|
||||
assert frood == frood2;
|
||||
|
@ -283,7 +283,7 @@ fn test_weaken_task_fail() {
|
||||
}
|
||||
}
|
||||
};
|
||||
assert result::is_err(res);
|
||||
assert result::is_err(&res);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -1,5 +1,9 @@
|
||||
//! A type representing either success or failure
|
||||
|
||||
// NB: transitionary, de-mode-ing.
|
||||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
use cmp::Eq;
|
||||
use either::Either;
|
||||
|
||||
@ -18,8 +22,8 @@ enum Result<T, U> {
|
||||
*
|
||||
* If the result is an error
|
||||
*/
|
||||
pure fn get<T: Copy, U>(res: Result<T, U>) -> T {
|
||||
match res {
|
||||
pure fn get<T: Copy, U>(res: &Result<T, U>) -> T {
|
||||
match *res {
|
||||
Ok(t) => t,
|
||||
Err(the_err) => unsafe {
|
||||
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
|
||||
*/
|
||||
pure fn get_err<T, U: Copy>(res: Result<T, U>) -> U {
|
||||
match res {
|
||||
pure fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
|
||||
match *res {
|
||||
Err(u) => u,
|
||||
Ok(_) => fail ~"get_err called on ok result"
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the result is `ok`
|
||||
pure fn is_ok<T, U>(res: Result<T, U>) -> bool {
|
||||
match res {
|
||||
pure fn is_ok<T, U>(res: &Result<T, U>) -> bool {
|
||||
match *res {
|
||||
Ok(_) => true,
|
||||
Err(_) => false
|
||||
}
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
||||
@ -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`
|
||||
* result variants are converted to `either::left`.
|
||||
*/
|
||||
pure fn to_either<T: Copy, U: Copy>(res: Result<U, T>) -> Either<T, U> {
|
||||
match res {
|
||||
pure fn to_either<T: Copy, U: Copy>(res: &Result<U, T>) -> Either<T, U> {
|
||||
match *res {
|
||||
Ok(res) => either::Right(res),
|
||||
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))
|
||||
* }
|
||||
*/
|
||||
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> {
|
||||
match res {
|
||||
Ok(t) => op(t),
|
||||
Err(e) => Err(e)
|
||||
// XXX: Should be writable with move + match
|
||||
if res.is_ok() {
|
||||
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.
|
||||
*/
|
||||
fn chain_err<T: Copy, U: Copy, V: Copy>(
|
||||
res: Result<T, V>,
|
||||
op: fn(V) -> Result<T, U>)
|
||||
+res: Result<T, V>,
|
||||
op: fn(+t: V) -> Result<T, U>)
|
||||
-> Result<T, U> {
|
||||
match res {
|
||||
move match res {
|
||||
Ok(t) => Ok(t),
|
||||
Err(v) => op(v)
|
||||
}
|
||||
@ -137,9 +143,9 @@ fn chain_err<T: Copy, U: Copy, V: Copy>(
|
||||
* print_buf(buf)
|
||||
* }
|
||||
*/
|
||||
fn iter<T, E>(res: Result<T, E>, f: fn(T)) {
|
||||
match res {
|
||||
Ok(t) => f(t),
|
||||
fn iter<T, E>(res: &Result<T, E>, f: fn((&T))) {
|
||||
match *res {
|
||||
Ok(t) => f(&t),
|
||||
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
|
||||
* handling an error.
|
||||
*/
|
||||
fn iter_err<T, E>(res: Result<T, E>, f: fn(E)) {
|
||||
match res {
|
||||
fn iter_err<T, E>(res: &Result<T, E>, f: fn((&E))) {
|
||||
match *res {
|
||||
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)
|
||||
* }
|
||||
*/
|
||||
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> {
|
||||
match res {
|
||||
Ok(t) => Ok(op(t)),
|
||||
match *res {
|
||||
Ok(t) => Ok(op(&t)),
|
||||
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
|
||||
* 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> {
|
||||
match res {
|
||||
match *res {
|
||||
Ok(t) => Ok(t),
|
||||
Err(e) => Err(op(e))
|
||||
Err(e) => Err(op(&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 {
|
||||
Ok(t) => f(t),
|
||||
Ok(t) => f(&t),
|
||||
Err(_) => ()
|
||||
}
|
||||
}
|
||||
|
||||
fn iter_err(f: fn(E)) {
|
||||
fn iter_err(f: fn((&E))) {
|
||||
match self {
|
||||
Ok(_) => (),
|
||||
Err(e) => f(e)
|
||||
Err(e) => f(&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 {
|
||||
Ok(t) => Ok(t),
|
||||
Err(e) => Err(op(e))
|
||||
Err(e) => Err(op(&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 {
|
||||
Ok(t) => Ok(op(t)),
|
||||
Ok(t) => Ok(op(&t)),
|
||||
Err(e) => Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy, E: Copy> Result<T, E> {
|
||||
fn chain<U:Copy>(op: fn(T) -> Result<U,E>) -> Result<U,E> {
|
||||
chain(self, op)
|
||||
fn chain<U:Copy>(op: fn(+t: T) -> Result<U,E>) -> Result<U,E> {
|
||||
// XXX: Bad copy
|
||||
chain(copy self, op)
|
||||
}
|
||||
|
||||
fn chain_err<F:Copy>(op: fn(E) -> Result<T,F>) -> Result<T,F> {
|
||||
chain_err(self, op)
|
||||
fn chain_err<F:Copy>(op: fn(+t: E) -> Result<T,F>) -> Result<T,F> {
|
||||
// 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>(
|
||||
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),
|
||||
Some(t) => match op(t) {
|
||||
Some(t) => match op(&t) {
|
||||
Ok(v) => Ok(Some(v)),
|
||||
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.
|
||||
*/
|
||||
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);
|
||||
let n = vec::len(ts);
|
||||
let mut vs = vec::with_capacity(n);
|
||||
let mut i = 0u;
|
||||
while i < n {
|
||||
match op(ss[i],ts[i]) {
|
||||
match op(&ss[i],&ts[i]) {
|
||||
Ok(v) => vec::push(vs, v),
|
||||
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.
|
||||
*/
|
||||
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);
|
||||
let n = vec::len(ts);
|
||||
let mut i = 0u;
|
||||
while i < n {
|
||||
match op(ss[i],ts[i]) {
|
||||
match op(&ss[i],&ts[i]) {
|
||||
Ok(()) => (),
|
||||
Err(u) => return Err(u)
|
||||
}
|
||||
@ -380,7 +388,7 @@ mod tests {
|
||||
#[legacy_exports];
|
||||
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)
|
||||
}
|
||||
|
||||
@ -388,12 +396,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn chain_success() {
|
||||
assert get(chain(op1(), op2)) == 667u;
|
||||
assert get(&chain(op1(), op2)) == 667u;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chain_failure() {
|
||||
assert get_err(chain(op3(), op2)) == ~"sadface";
|
||||
assert get_err(&chain(op3(), op2)) == ~"sadface";
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -892,7 +892,7 @@ mod tests {
|
||||
]))
|
||||
]);
|
||||
let astr = to_str(a);
|
||||
let b = result::get(from_str(astr));
|
||||
let b = result::get(&from_str(astr));
|
||||
let bstr = to_str(b);
|
||||
assert astr == bstr;
|
||||
assert a == b;
|
||||
@ -1040,24 +1040,24 @@ mod tests {
|
||||
assert from_str(~"{\"a\":1,") ==
|
||||
Err({line: 1u, col: 8u, msg: @~"EOF while parsing object"});
|
||||
|
||||
assert eq(result::get(from_str(~"{}")), mk_dict(~[]));
|
||||
assert eq(result::get(from_str(~"{\"a\": 3}")),
|
||||
assert eq(result::get(&from_str(~"{}")), mk_dict(~[]));
|
||||
assert eq(result::get(&from_str(~"{\"a\": 3}")),
|
||||
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(~[
|
||||
(~"a", Null),
|
||||
(~"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(~[
|
||||
(~"a", Null),
|
||||
(~"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(~[
|
||||
(~"a", Num(1.0)),
|
||||
(~"b", List(@~[Boolean(true)]))
|
||||
]));
|
||||
assert eq(result::get(from_str(
|
||||
assert eq(result::get(&from_str(
|
||||
~"{" +
|
||||
~"\"a\": 1.0, " +
|
||||
~"\"b\": [" +
|
||||
|
@ -176,24 +176,24 @@ mod v4 {
|
||||
unsafe {
|
||||
let INADDR_NONE = ll::get_INADDR_NONE();
|
||||
let ip_rep_result = parse_to_ipv4_rep(ip);
|
||||
if result::is_err(ip_rep_result) {
|
||||
let err_str = result::get_err(ip_rep_result);
|
||||
if result::is_err(&ip_rep_result) {
|
||||
let err_str = result::get_err(&ip_rep_result);
|
||||
return result::Err({err_msg: err_str})
|
||||
}
|
||||
// ipv4_rep.as_u32 is unsafe :/
|
||||
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 reformatted_name = uv_ip4_name(&new_addr);
|
||||
log(debug, fmt!("try_parse_addr: input ip: %s reparsed ip: %s",
|
||||
ip, reformatted_name));
|
||||
let ref_ip_rep_result = parse_to_ipv4_rep(reformatted_name);
|
||||
if result::is_err(ref_ip_rep_result) {
|
||||
let err_str = result::get_err(ref_ip_rep_result);
|
||||
if result::is_err(&ref_ip_rep_result) {
|
||||
let err_str = result::get_err(&ref_ip_rep_result);
|
||||
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 {
|
||||
return result::Err(
|
||||
{err_msg: ~"uv_ip4_name produced invalid result."})
|
||||
@ -358,7 +358,7 @@ mod test {
|
||||
let localhost_name = ~"localhost";
|
||||
let iotask = uv::global_loop::get();
|
||||
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();"
|
||||
}
|
||||
// note really sure how to realiably test/assert
|
||||
@ -384,6 +384,6 @@ mod test {
|
||||
let localhost_name = ~"sjkl234m,./sdf";
|
||||
let iotask = uv::global_loop::get();
|
||||
let ga_result = get_addr(localhost_name, iotask);
|
||||
assert result::is_err(ga_result);
|
||||
assert result::is_err(&ga_result);
|
||||
}
|
||||
}
|
||||
|
@ -871,17 +871,17 @@ fn read_common_impl(socket_data: *TcpSocketData, timeout_msecs: uint)
|
||||
log(debug, ~"starting tcp::read");
|
||||
let iotask = (*socket_data).iotask;
|
||||
let rs_result = read_start_common_impl(socket_data);
|
||||
if result::is_err(rs_result) {
|
||||
let err_data = result::get_err(rs_result);
|
||||
if result::is_err(&rs_result) {
|
||||
let err_data = result::get_err(&rs_result);
|
||||
result::Err(err_data)
|
||||
}
|
||||
else {
|
||||
log(debug, ~"tcp::read before recv_timeout");
|
||||
let read_result = if timeout_msecs > 0u {
|
||||
timer::recv_timeout(
|
||||
iotask, timeout_msecs, result::get(rs_result))
|
||||
iotask, timeout_msecs, result::get(&rs_result))
|
||||
} else {
|
||||
Some(core::comm::recv(result::get(rs_result)))
|
||||
Some(core::comm::recv(result::get(&rs_result)))
|
||||
};
|
||||
log(debug, ~"tcp::read after recv_timeout");
|
||||
match read_result {
|
||||
@ -1514,9 +1514,9 @@ mod test {
|
||||
|
||||
let accept_result = accept(new_conn);
|
||||
log(debug, ~"SERVER: after accept()");
|
||||
if result::is_err(accept_result) {
|
||||
if result::is_err(&accept_result) {
|
||||
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));
|
||||
log(debug,
|
||||
~"SERVER/WORKER: send on err cont ch");
|
||||
@ -1558,8 +1558,8 @@ mod test {
|
||||
log(debug, ~"SERVER: recv'd on cont_ch..leaving listen cb");
|
||||
});
|
||||
// err check on listen_result
|
||||
if result::is_err(listen_result) {
|
||||
match result::get_err(listen_result) {
|
||||
if result::is_err(&listen_result) {
|
||||
match result::get_err(&listen_result) {
|
||||
GenericListenErr(name, msg) => {
|
||||
fail fmt!("SERVER: exited abnormally name %s msg %s",
|
||||
name, msg);
|
||||
@ -1592,8 +1592,8 @@ mod test {
|
||||
new_conn, kill_ch);
|
||||
});
|
||||
// err check on listen_result
|
||||
if result::is_err(listen_result) {
|
||||
result::get_err(listen_result)
|
||||
if result::is_err(&listen_result) {
|
||||
result::get_err(&listen_result)
|
||||
}
|
||||
else {
|
||||
fail ~"SERVER: did not fail as expected"
|
||||
@ -1609,9 +1609,9 @@ mod test {
|
||||
log(debug, ~"CLIENT: starting..");
|
||||
let connect_result = connect(move server_ip_addr, server_port,
|
||||
iotask);
|
||||
if result::is_err(connect_result) {
|
||||
if result::is_err(&connect_result) {
|
||||
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)
|
||||
}
|
||||
else {
|
||||
@ -1636,9 +1636,9 @@ mod test {
|
||||
fn tcp_write_single(sock: &TcpSocket, val: ~[u8]) {
|
||||
let write_result_future = sock.write_future(val);
|
||||
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!");
|
||||
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",
|
||||
err_data.err_name, err_data.err_msg));
|
||||
// meh. torn on what to do here.
|
||||
|
@ -627,30 +627,30 @@ fn get_query_fragment(rawurl: &str) ->
|
||||
fn from_str(rawurl: &str) -> result::Result<Url, ~str> {
|
||||
// scheme
|
||||
let mut schm = get_scheme(rawurl);
|
||||
if result::is_err(schm) {
|
||||
return result::Err(copy *result::get_err(schm));
|
||||
if result::is_err(&schm) {
|
||||
return result::Err(copy *result::get_err(&schm));
|
||||
}
|
||||
let (scheme, rest) = result::unwrap(schm);
|
||||
|
||||
// authority
|
||||
let mut auth = get_authority(rest);
|
||||
if result::is_err(auth) {
|
||||
return result::Err(copy *result::get_err(auth));
|
||||
if result::is_err(&auth) {
|
||||
return result::Err(copy *result::get_err(&auth));
|
||||
}
|
||||
let (userinfo, host, port, rest) = result::unwrap(auth);
|
||||
|
||||
// path
|
||||
let has_authority = if host == ~"" { false } else { true };
|
||||
let mut pth = get_path(rest, has_authority);
|
||||
if result::is_err(pth) {
|
||||
return result::Err(copy *result::get_err(pth));
|
||||
if result::is_err(&pth) {
|
||||
return result::Err(copy *result::get_err(&pth));
|
||||
}
|
||||
let (path, rest) = result::unwrap(pth);
|
||||
|
||||
// query and fragment
|
||||
let mut qry = get_query_fragment(rest);
|
||||
if result::is_err(qry) {
|
||||
return result::Err(copy *result::get_err(qry));
|
||||
if result::is_err(&qry) {
|
||||
return result::Err(copy *result::get_err(&qry));
|
||||
}
|
||||
let (query, fragment) = result::unwrap(qry);
|
||||
|
||||
@ -796,13 +796,13 @@ mod tests {
|
||||
assert p == option::Some(~"8000");
|
||||
|
||||
// invalid authorities;
|
||||
assert result::is_err(get_authority(
|
||||
assert result::is_err(&get_authority(
|
||||
~"//user:pass@rust-lang:something"));
|
||||
assert result::is_err(get_authority(
|
||||
assert result::is_err(&get_authority(
|
||||
~"//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"));
|
||||
assert result::is_err(get_authority(
|
||||
assert result::is_err(&get_authority(
|
||||
~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00"));
|
||||
|
||||
// these parse as empty, because they don't start with '//'
|
||||
@ -830,7 +830,7 @@ mod tests {
|
||||
assert r == ~"?q=v";
|
||||
|
||||
//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]
|
||||
fn test_no_scheme() {
|
||||
assert result::is_err(get_scheme(~"noschemehere.html"));
|
||||
assert result::is_err(&get_scheme(~"noschemehere.html"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_scheme_errors() {
|
||||
assert result::is_err(from_str(~"99://something"));
|
||||
assert result::is_err(from_str(~"://something"));
|
||||
assert result::is_err(&from_str(~"99://something"));
|
||||
assert result::is_err(&from_str(~"://something"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -415,7 +415,7 @@ fn ty_of_arg<AC: ast_conv, RS: region_scope Copy Owned>(
|
||||
let mode = {
|
||||
match a.mode {
|
||||
ast::infer(_) if expected_ty.is_some() => {
|
||||
result::get(ty::unify_mode(
|
||||
result::get(&ty::unify_mode(
|
||||
self.tcx(),
|
||||
ty::expected_found {expected: expected_ty.get().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(),
|
||||
ty));
|
||||
result::get(ty::unify_mode(
|
||||
result::get(&ty::unify_mode(
|
||||
self.tcx(),
|
||||
ty::expected_found {expected: m1,
|
||||
found: a.mode}))
|
||||
|
@ -221,7 +221,7 @@ fn super_tps<C:combine>(
|
||||
|
||||
if vec::same_length(as_, bs) {
|
||||
iter_vec2(as_, bs, |a, b| {
|
||||
eq_tys(self, a, b)
|
||||
eq_tys(self, *a, *b)
|
||||
}).then(|| Ok(as_.to_vec()) )
|
||||
} else {
|
||||
Err(ty::terr_ty_param_size(
|
||||
@ -327,7 +327,7 @@ fn super_fn_sigs<C:combine>(
|
||||
b_args: ~[ty::arg]) -> cres<~[ty::arg]> {
|
||||
|
||||
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 {
|
||||
Err(ty::terr_arg_count)
|
||||
}
|
||||
@ -474,7 +474,7 @@ fn super_tys<C:combine>(
|
||||
(ty::ty_rec(as_), ty::ty_rec(bs)) => {
|
||||
if vec::same_length(as_, bs) {
|
||||
map_vec2(as_, bs, |a,b| {
|
||||
self.flds(a, b)
|
||||
self.flds(*a, *b)
|
||||
}).chain(|flds| Ok(ty::mk_rec(tcx, flds)) )
|
||||
} else {
|
||||
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)) => {
|
||||
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)) )
|
||||
} else {
|
||||
Err(ty::terr_tuple_size(
|
||||
|
@ -285,20 +285,20 @@ mod test {
|
||||
#[test]
|
||||
fn should_error_with_no_crates() {
|
||||
let config = test::parse_config(~[~"rustdoc"]);
|
||||
assert result::get_err(config) == ~"no crates specified";
|
||||
assert config.get_err() == ~"no crates specified";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_error_with_multiple_crates() {
|
||||
let config =
|
||||
test::parse_config(~[~"rustdoc", ~"crate1.rc", ~"crate2.rc"]);
|
||||
assert result::get_err(config) == ~"multiple crates specified";
|
||||
assert config.get_err() == ~"multiple crates specified";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_set_output_dir_to_cwd_if_not_provided() {
|
||||
let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]);
|
||||
assert result::get(config).output_dir == Path(".");
|
||||
assert config.get().output_dir == Path(".");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -306,13 +306,13 @@ fn should_set_output_dir_if_provided() {
|
||||
let config = test::parse_config(~[
|
||||
~"rustdoc", ~"crate.rc", ~"--output-dir", ~"snuggles"
|
||||
]);
|
||||
assert result::get(config).output_dir == Path("snuggles");
|
||||
assert config.get().output_dir == Path("snuggles");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_set_output_format_to_pandoc_html_if_not_provided() {
|
||||
let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]);
|
||||
assert result::get(config).output_format == PandocHtml;
|
||||
assert config.get().output_format == PandocHtml;
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -320,7 +320,7 @@ fn should_set_output_format_to_markdown_if_requested() {
|
||||
let config = test::parse_config(~[
|
||||
~"rustdoc", ~"crate.rc", ~"--output-format", ~"markdown"
|
||||
]);
|
||||
assert result::get(config).output_format == Markdown;
|
||||
assert config.get().output_format == Markdown;
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -328,7 +328,7 @@ fn should_set_output_format_to_pandoc_html_if_requested() {
|
||||
let config = test::parse_config(~[
|
||||
~"rustdoc", ~"crate.rc", ~"--output-format", ~"html"
|
||||
]);
|
||||
assert result::get(config).output_format == PandocHtml;
|
||||
assert config.get().output_format == PandocHtml;
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -336,13 +336,13 @@ fn should_error_on_bogus_format() {
|
||||
let config = test::parse_config(~[
|
||||
~"rustdoc", ~"crate.rc", ~"--output-format", ~"bogus"
|
||||
]);
|
||||
assert result::get_err(config) == ~"unknown output format 'bogus'";
|
||||
assert config.get_err() == ~"unknown output format 'bogus'";
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_set_output_style_to_doc_per_mod_by_default() {
|
||||
let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]);
|
||||
assert result::get(config).output_style == DocPerMod;
|
||||
assert config.get().output_style == DocPerMod;
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -350,7 +350,7 @@ fn should_set_output_style_to_one_doc_if_requested() {
|
||||
let config = test::parse_config(~[
|
||||
~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-crate"
|
||||
]);
|
||||
assert result::get(config).output_style == DocPerCrate;
|
||||
assert config.get().output_style == DocPerCrate;
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -358,7 +358,7 @@ fn should_set_output_style_to_doc_per_mod_if_requested() {
|
||||
let config = test::parse_config(~[
|
||||
~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-mod"
|
||||
]);
|
||||
assert result::get(config).output_style == DocPerMod;
|
||||
assert config.get().output_style == DocPerMod;
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -366,7 +366,7 @@ fn should_error_on_bogus_output_style() {
|
||||
let config = test::parse_config(~[
|
||||
~"rustdoc", ~"crate.rc", ~"--output-style", ~"bogus"
|
||||
]);
|
||||
assert result::get_err(config) == ~"unknown output style 'bogus'";
|
||||
assert config.get_err() == ~"unknown output style 'bogus'";
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -374,11 +374,11 @@ fn should_set_pandoc_command_if_requested() {
|
||||
let config = test::parse_config(~[
|
||||
~"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]
|
||||
fn should_set_pandoc_command_when_using_pandoc() {
|
||||
let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]);
|
||||
assert result::get(config).pandoc_cmd == Some(~"pandoc");
|
||||
assert config.get().pandoc_cmd == Some(~"pandoc");
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ fn read_line() {
|
||||
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
||||
|
||||
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() {
|
||||
reader.read_line();
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ fn main(++args: ~[~str]) {
|
||||
};
|
||||
|
||||
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]))
|
||||
} else {
|
||||
io::stdout()
|
||||
|
@ -134,7 +134,7 @@ fn main(++args: ~[~str]) {
|
||||
// get to this massive data set, but #include_bin chokes on it (#2598)
|
||||
let path = Path(env!("CFG_SRC_DIR"))
|
||||
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
||||
result::get(io::file_reader(&path))
|
||||
result::get(&io::file_reader(&path))
|
||||
} else {
|
||||
io::stdin()
|
||||
};
|
||||
|
@ -131,7 +131,7 @@ fn main(++args: ~[~str]) {
|
||||
// get to this massive data set, but #include_bin chokes on it (#2598)
|
||||
let path = Path(env!("CFG_SRC_DIR"))
|
||||
.push_rel(&Path("src/test/bench/shootout-k-nucleotide.data"));
|
||||
result::get(io::file_reader(&path))
|
||||
result::get(&io::file_reader(&path))
|
||||
} else {
|
||||
io::stdin()
|
||||
};
|
||||
|
@ -114,7 +114,7 @@ fn writer(path: ~str, writech: comm::Chan<comm::Chan<line>>, size: uint)
|
||||
}
|
||||
_ => {
|
||||
result::get(
|
||||
io::file_writer(&Path(path),
|
||||
&io::file_writer(&Path(path),
|
||||
~[io::Create, io::Truncate]))
|
||||
}
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
// error-pattern:get called on error result: ~"kitty"
|
||||
fn main() {
|
||||
log(error, result::get(result::Err::<int,~str>(~"kitty")));
|
||||
log(error, result::get(&result::Err::<int,~str>(~"kitty")));
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
fn adder(+x: @int, +y: @int) -> int { return *x + *y; }
|
||||
fn failer() -> @int { fail; }
|
||||
fn main() {
|
||||
assert(result::is_err(task::try(|| {
|
||||
assert(result::is_err(&task::try(|| {
|
||||
adder(@2, failer()); ()
|
||||
})));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user