diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-08-26 16:54:31 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-27 14:37:04 -0700 |
| commit | 0c6e470a257fc546555aa10ededded4a77460a71 (patch) | |
| tree | fb54281612401dba521efedab7626474c80195a9 /src/libstd | |
| parent | 3a1582012eafb8b672e15b12b5424e72ea6096af (diff) | |
Convert core::result to camel case
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/getopts.rs | 96 | ||||
| -rw-r--r-- | src/libstd/json.rs | 216 | ||||
| -rw-r--r-- | src/libstd/net_ip.rs | 54 | ||||
| -rw-r--r-- | src/libstd/net_tcp.rs | 106 | ||||
| -rw-r--r-- | src/libstd/net_url.rs | 62 | ||||
| -rw-r--r-- | src/libstd/sync.rs | 8 | ||||
| -rw-r--r-- | src/libstd/test.rs | 10 | ||||
| -rw-r--r-- | src/libstd/time.rs | 132 |
8 files changed, 342 insertions, 342 deletions
diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index ea62f3cc3c4..bf85f19a516 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -62,7 +62,7 @@ * } */ -import core::result::{err, ok}; +import core::result::{Err, Ok}; import core::option; import core::option::{Some, None}; export opt; @@ -179,7 +179,7 @@ fn fail_str(f: fail_) -> ~str { * The result of parsing a command line with a set of options * (result::t<matches, fail_>) */ -type result = result::result<matches, fail_>; +type result = result::Result<matches, fail_>; /** * Parse command line arguments according to the provided options @@ -261,12 +261,12 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe { name_pos += 1u; let optid = match find_opt(opts, nm) { Some(id) => id, - None => return err(unrecognized_option(name_str(nm))) + None => return Err(unrecognized_option(name_str(nm))) }; match opts[optid].hasarg { no => { if !option::is_none::<~str>(i_arg) { - return err(unexpected_argument(name_str(nm))); + return Err(unexpected_argument(name_str(nm))); } vec::push(vals[optid], given); } @@ -283,7 +283,7 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe { vec::push(vals[optid], val(option::get::<~str>(i_arg))); } else if i + 1u == l { - return err(argument_missing(name_str(nm))); + return Err(argument_missing(name_str(nm))); } else { i += 1u; vec::push(vals[optid], val(args[i])); } } } @@ -297,17 +297,17 @@ fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe { let occ = opts[i].occur; if occ == req { if n == 0u { - return err(option_missing(name_str(opts[i].name))); + return Err(option_missing(name_str(opts[i].name))); } } if occ != multi { if n > 1u { - return err(option_duplicated(name_str(opts[i].name))); + return Err(option_duplicated(name_str(opts[i].name))); } } i += 1u; } - return ok({opts: opts, vals: vec::from_mut(vals), free: free}); + return Ok({opts: opts, vals: vec::from_mut(vals), free: free}); } fn opt_vals(m: matches, nm: ~str) -> ~[optval] { @@ -404,7 +404,7 @@ fn opt_default(m: matches, nm: ~str, def: ~str) -> Option<~str> { #[cfg(test)] mod tests { import opt = getopts; - import result::{err, ok}; + import result::{Err, Ok}; enum fail_type { argument_missing_, @@ -432,7 +432,7 @@ mod tests { let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); match rs { - ok(m) => { + Ok(m) => { assert (opt_present(m, ~"test")); assert (opt_str(m, ~"test") == ~"20"); } @@ -446,7 +446,7 @@ mod tests { let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, option_missing_), + Err(f) => check_fail_type(f, option_missing_), _ => fail } } @@ -457,7 +457,7 @@ mod tests { let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, argument_missing_), + Err(f) => check_fail_type(f, argument_missing_), _ => fail } } @@ -468,7 +468,7 @@ mod tests { let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, option_duplicated_), + Err(f) => check_fail_type(f, option_duplicated_), _ => fail } } @@ -479,7 +479,7 @@ mod tests { let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); match rs { - ok(m) => { + Ok(m) => { assert (opt_present(m, ~"t")); assert (opt_str(m, ~"t") == ~"20"); } @@ -493,7 +493,7 @@ mod tests { let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, option_missing_), + Err(f) => check_fail_type(f, option_missing_), _ => fail } } @@ -504,7 +504,7 @@ mod tests { let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, argument_missing_), + Err(f) => check_fail_type(f, argument_missing_), _ => fail } } @@ -515,7 +515,7 @@ mod tests { let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, option_duplicated_), + Err(f) => check_fail_type(f, option_duplicated_), _ => fail } } @@ -528,7 +528,7 @@ mod tests { let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); match rs { - ok(m) => { + Ok(m) => { assert (opt_present(m, ~"test")); assert (opt_str(m, ~"test") == ~"20"); } @@ -542,7 +542,7 @@ mod tests { let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); match rs { - ok(m) => assert (!opt_present(m, ~"test")), + Ok(m) => assert (!opt_present(m, ~"test")), _ => fail } } @@ -553,7 +553,7 @@ mod tests { let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, argument_missing_), + Err(f) => check_fail_type(f, argument_missing_), _ => fail } } @@ -564,7 +564,7 @@ mod tests { let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, option_duplicated_), + Err(f) => check_fail_type(f, option_duplicated_), _ => fail } } @@ -575,7 +575,7 @@ mod tests { let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); match rs { - ok(m) => { + Ok(m) => { assert (opt_present(m, ~"t")); assert (opt_str(m, ~"t") == ~"20"); } @@ -589,7 +589,7 @@ mod tests { let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); match rs { - ok(m) => assert (!opt_present(m, ~"t")), + Ok(m) => assert (!opt_present(m, ~"t")), _ => fail } } @@ -600,7 +600,7 @@ mod tests { let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, argument_missing_), + Err(f) => check_fail_type(f, argument_missing_), _ => fail } } @@ -611,7 +611,7 @@ mod tests { let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, option_duplicated_), + Err(f) => check_fail_type(f, option_duplicated_), _ => fail } } @@ -624,7 +624,7 @@ mod tests { let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); match rs { - ok(m) => assert (opt_present(m, ~"test")), + Ok(m) => assert (opt_present(m, ~"test")), _ => fail } } @@ -635,7 +635,7 @@ mod tests { let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); match rs { - ok(m) => assert (!opt_present(m, ~"test")), + Ok(m) => assert (!opt_present(m, ~"test")), _ => fail } } @@ -646,7 +646,7 @@ mod tests { let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); match rs { - err(f) => { + Err(f) => { log(error, fail_str(f)); check_fail_type(f, unexpected_argument_); } @@ -660,7 +660,7 @@ mod tests { let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, option_duplicated_), + Err(f) => check_fail_type(f, option_duplicated_), _ => fail } } @@ -671,7 +671,7 @@ mod tests { let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); match rs { - ok(m) => assert (opt_present(m, ~"t")), + Ok(m) => assert (opt_present(m, ~"t")), _ => fail } } @@ -682,7 +682,7 @@ mod tests { let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); match rs { - ok(m) => assert (!opt_present(m, ~"t")), + Ok(m) => assert (!opt_present(m, ~"t")), _ => fail } } @@ -693,7 +693,7 @@ mod tests { let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); match rs { - ok(m) => { + Ok(m) => { // The next variable after the flag is just a free argument assert (m.free[0] == ~"20"); @@ -708,7 +708,7 @@ mod tests { let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, option_duplicated_), + Err(f) => check_fail_type(f, option_duplicated_), _ => fail } } @@ -721,7 +721,7 @@ mod tests { let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); match rs { - ok(m) => { + Ok(m) => { assert (opt_present(m, ~"test")); assert (opt_str(m, ~"test") == ~"20"); } @@ -735,7 +735,7 @@ mod tests { let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); match rs { - ok(m) => assert (!opt_present(m, ~"test")), + Ok(m) => assert (!opt_present(m, ~"test")), _ => fail } } @@ -746,7 +746,7 @@ mod tests { let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, argument_missing_), + Err(f) => check_fail_type(f, argument_missing_), _ => fail } } @@ -757,7 +757,7 @@ mod tests { let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); match rs { - ok(m) => { + Ok(m) => { assert (opt_present(m, ~"test")); assert (opt_str(m, ~"test") == ~"20"); assert (opt_strs(m, ~"test")[0] == ~"20"); @@ -773,7 +773,7 @@ mod tests { let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); match rs { - ok(m) => { + Ok(m) => { assert (opt_present(m, ~"t")); assert (opt_str(m, ~"t") == ~"20"); } @@ -787,7 +787,7 @@ mod tests { let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); match rs { - ok(m) => assert (!opt_present(m, ~"t")), + Ok(m) => assert (!opt_present(m, ~"t")), _ => fail } } @@ -798,7 +798,7 @@ mod tests { let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, argument_missing_), + Err(f) => check_fail_type(f, argument_missing_), _ => fail } } @@ -809,7 +809,7 @@ mod tests { let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); match rs { - ok(m) => { + Ok(m) => { assert (opt_present(m, ~"t")); assert (opt_str(m, ~"t") == ~"20"); assert (opt_strs(m, ~"t")[0] == ~"20"); @@ -825,7 +825,7 @@ mod tests { let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, unrecognized_option_), + Err(f) => check_fail_type(f, unrecognized_option_), _ => fail } } @@ -836,7 +836,7 @@ mod tests { let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); match rs { - err(f) => check_fail_type(f, unrecognized_option_), + Err(f) => check_fail_type(f, unrecognized_option_), _ => fail } } @@ -853,7 +853,7 @@ mod tests { optopt(~"notpresent")]; let rs = getopts(args, opts); match rs { - ok(m) => { + Ok(m) => { assert (m.free[0] == ~"prog"); assert (m.free[1] == ~"free1"); assert (opt_str(m, ~"s") == ~"20"); @@ -876,8 +876,8 @@ mod tests { let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"]; let opts = ~[optopt(~"e"), optopt(~"encrypt")]; let matches = match getopts(args, opts) { - result::ok(m) => m, - result::err(_) => fail + result::Ok(m) => m, + result::Err(_) => fail }; assert opts_present(matches, ~[~"e"]); assert opts_present(matches, ~[~"encrypt"]); @@ -897,8 +897,8 @@ mod tests { let args = ~[~"-Lfoo"]; let opts = ~[optmulti(~"L")]; let matches = match getopts(args, opts) { - result::ok(m) => m, - result::err(_) => fail + result::Ok(m) => m, + result::Err(_) => fail }; assert opts_present(matches, ~[~"L"]); assert opts_str(matches, ~[~"L"]) == ~"foo"; diff --git a/src/libstd/json.rs b/src/libstd/json.rs index d0571059e86..aec68965e66 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -3,7 +3,7 @@ //! json serialization -import result::{result, ok, err}; +import result::{Result, Ok, Err}; import io; import io::WriterUtil; import map; @@ -138,18 +138,18 @@ impl parser { self.ch } - fn error<T>(+msg: ~str) -> result<T, error> { - err({ line: self.line, col: self.col, msg: @msg }) + fn error<T>(+msg: ~str) -> Result<T, error> { + Err({ line: self.line, col: self.col, msg: @msg }) } - fn parse() -> result<json, error> { + fn parse() -> Result<json, error> { match self.parse_value() { - ok(value) => { + Ok(value) => { // Skip trailing whitespaces. self.parse_whitespace(); // Make sure there is no trailing characters. if self.eof() { - ok(value) + Ok(value) } else { self.error(~"trailing characters") } @@ -158,7 +158,7 @@ impl parser { } } - fn parse_value() -> result<json, error> { + fn parse_value() -> Result<json, error> { self.parse_whitespace(); if self.eof() { return self.error(~"EOF while parsing value"); } @@ -169,8 +169,8 @@ impl parser { 'f' => self.parse_ident(~"alse", boolean(false)), '0' to '9' | '-' => self.parse_number(), '"' => match self.parse_str() { - ok(s) => ok(string(s)), - err(e) => err(e) + Ok(s) => Ok(string(s)), + Err(e) => Err(e) }, '[' => self.parse_list(), '{' => self.parse_object(), @@ -182,16 +182,16 @@ impl parser { while char::is_whitespace(self.ch) { self.bump(); } } - fn parse_ident(ident: ~str, value: json) -> result<json, error> { + fn parse_ident(ident: ~str, value: json) -> Result<json, error> { if str::all(ident, |c| c == self.next_char()) { self.bump(); - ok(value) + Ok(value) } else { self.error(~"invalid syntax") } } - fn parse_number() -> result<json, error> { + fn parse_number() -> Result<json, error> { let mut neg = 1f; if self.ch == '-' { @@ -200,28 +200,28 @@ impl parser { } let mut res = match self.parse_integer() { - ok(res) => res, - err(e) => return err(e) + Ok(res) => res, + Err(e) => return Err(e) }; if self.ch == '.' { match self.parse_decimal(res) { - ok(r) => res = r, - err(e) => return err(e) + Ok(r) => res = r, + Err(e) => return Err(e) } } if self.ch == 'e' || self.ch == 'E' { match self.parse_exponent(res) { - ok(r) => res = r, - err(e) => return err(e) + Ok(r) => res = r, + Err(e) => return Err(e) } } - ok(num(neg * res)) + Ok(num(neg * res)) } - fn parse_integer() -> result<float, error> { + fn parse_integer() -> Result<float, error> { let mut res = 0f; match self.ch { @@ -250,10 +250,10 @@ impl parser { _ => return self.error(~"invalid number") } - ok(res) + Ok(res) } - fn parse_decimal(res: float) -> result<float, error> { + fn parse_decimal(res: float) -> Result<float, error> { self.bump(); // Make sure a digit follows the decimal place. @@ -276,10 +276,10 @@ impl parser { } } - ok(res) + Ok(res) } - fn parse_exponent(res: float) -> result<float, error> { + fn parse_exponent(res: float) -> Result<float, error> { self.bump(); let mut res = res; @@ -317,10 +317,10 @@ impl parser { res *= exp; } - ok(res) + Ok(res) } - fn parse_str() -> result<@~str, error> { + fn parse_str() -> Result<@~str, error> { let mut escape = false; let mut res = ~""; @@ -367,7 +367,7 @@ impl parser { } else { if self.ch == '"' { self.bump(); - return ok(@res); + return Ok(@res); } str::push_char(res, self.ch); } @@ -376,7 +376,7 @@ impl parser { self.error(~"EOF while parsing string") } - fn parse_list() -> result<json, error> { + fn parse_list() -> Result<json, error> { self.bump(); self.parse_whitespace(); @@ -384,12 +384,12 @@ impl parser { if self.ch == ']' { self.bump(); - return ok(list(@values)); + return Ok(list(@values)); } loop { match self.parse_value() { - ok(v) => vec::push(values, v), + Ok(v) => vec::push(values, v), e => return e } @@ -400,13 +400,13 @@ impl parser { match self.ch { ',' => self.bump(), - ']' => { self.bump(); return ok(list(@values)); } + ']' => { self.bump(); return Ok(list(@values)); } _ => return self.error(~"expected `,` or `]`") } }; } - fn parse_object() -> result<json, error> { + fn parse_object() -> Result<json, error> { self.bump(); self.parse_whitespace(); @@ -414,7 +414,7 @@ impl parser { if self.ch == '}' { self.bump(); - return ok(dict(values)); + return Ok(dict(values)); } while !self.eof() { @@ -425,8 +425,8 @@ impl parser { } let key = match self.parse_str() { - ok(key) => key, - err(e) => return err(e) + Ok(key) => key, + Err(e) => return Err(e) }; self.parse_whitespace(); @@ -438,14 +438,14 @@ impl parser { self.bump(); match self.parse_value() { - ok(value) => { values.insert(copy *key, value); } + Ok(value) => { values.insert(copy *key, value); } e => return e } self.parse_whitespace(); match self.ch { ',' => self.bump(), - '}' => { self.bump(); return ok(dict(values)); } + '}' => { self.bump(); return Ok(dict(values)); } _ => { if self.eof() { break; } return self.error(~"expected `,` or `}`"); @@ -458,7 +458,7 @@ impl parser { } /// Deserializes a json value from an io::reader -fn from_reader(rdr: io::Reader) -> result<json, error> { +fn from_reader(rdr: io::Reader) -> Result<json, error> { let parser = parser_({ rdr: rdr, mut ch: rdr.read_char(), @@ -470,7 +470,7 @@ fn from_reader(rdr: io::Reader) -> result<json, error> { } /// Deserializes a json value from a string -fn from_str(s: ~str) -> result<json, error> { +fn from_str(s: ~str) -> Result<json, error> { io::with_str_reader(s, from_reader) } @@ -705,138 +705,138 @@ mod tests { #[test] fn test_trailing_characters() { assert from_str(~"nulla") == - err({line: 1u, col: 5u, msg: @~"trailing characters"}); + Err({line: 1u, col: 5u, msg: @~"trailing characters"}); assert from_str(~"truea") == - err({line: 1u, col: 5u, msg: @~"trailing characters"}); + Err({line: 1u, col: 5u, msg: @~"trailing characters"}); assert from_str(~"falsea") == - err({line: 1u, col: 6u, msg: @~"trailing characters"}); + Err({line: 1u, col: 6u, msg: @~"trailing characters"}); assert from_str(~"1a") == - err({line: 1u, col: 2u, msg: @~"trailing characters"}); + Err({line: 1u, col: 2u, msg: @~"trailing characters"}); assert from_str(~"[]a") == - err({line: 1u, col: 3u, msg: @~"trailing characters"}); + Err({line: 1u, col: 3u, msg: @~"trailing characters"}); assert from_str(~"{}a") == - err({line: 1u, col: 3u, msg: @~"trailing characters"}); + Err({line: 1u, col: 3u, msg: @~"trailing characters"}); } #[test] fn test_read_identifiers() { assert from_str(~"n") == - err({line: 1u, col: 2u, msg: @~"invalid syntax"}); + Err({line: 1u, col: 2u, msg: @~"invalid syntax"}); assert from_str(~"nul") == - err({line: 1u, col: 4u, msg: @~"invalid syntax"}); + Err({line: 1u, col: 4u, msg: @~"invalid syntax"}); assert from_str(~"t") == - err({line: 1u, col: 2u, msg: @~"invalid syntax"}); + Err({line: 1u, col: 2u, msg: @~"invalid syntax"}); assert from_str(~"truz") == - err({line: 1u, col: 4u, msg: @~"invalid syntax"}); + Err({line: 1u, col: 4u, msg: @~"invalid syntax"}); assert from_str(~"f") == - err({line: 1u, col: 2u, msg: @~"invalid syntax"}); + Err({line: 1u, col: 2u, msg: @~"invalid syntax"}); assert from_str(~"faz") == - err({line: 1u, col: 3u, msg: @~"invalid syntax"}); + Err({line: 1u, col: 3u, msg: @~"invalid syntax"}); - assert from_str(~"null") == ok(null); - assert from_str(~"true") == ok(boolean(true)); - assert from_str(~"false") == ok(boolean(false)); - assert from_str(~" null ") == ok(null); - assert from_str(~" true ") == ok(boolean(true)); - assert from_str(~" false ") == ok(boolean(false)); + assert from_str(~"null") == Ok(null); + assert from_str(~"true") == Ok(boolean(true)); + assert from_str(~"false") == Ok(boolean(false)); + assert from_str(~" null ") == Ok(null); + assert from_str(~" true ") == Ok(boolean(true)); + assert from_str(~" false ") == Ok(boolean(false)); } #[test] fn test_read_num() { assert from_str(~"+") == - err({line: 1u, col: 1u, msg: @~"invalid syntax"}); + Err({line: 1u, col: 1u, msg: @~"invalid syntax"}); assert from_str(~".") == - err({line: 1u, col: 1u, msg: @~"invalid syntax"}); + Err({line: 1u, col: 1u, msg: @~"invalid syntax"}); assert from_str(~"-") == - err({line: 1u, col: 2u, msg: @~"invalid number"}); + Err({line: 1u, col: 2u, msg: @~"invalid number"}); assert from_str(~"00") == - err({line: 1u, col: 2u, msg: @~"invalid number"}); + Err({line: 1u, col: 2u, msg: @~"invalid number"}); assert from_str(~"1.") == - err({line: 1u, col: 3u, msg: @~"invalid number"}); + Err({line: 1u, col: 3u, msg: @~"invalid number"}); assert from_str(~"1e") == - err({line: 1u, col: 3u, msg: @~"invalid number"}); + Err({line: 1u, col: 3u, msg: @~"invalid number"}); assert from_str(~"1e+") == - err({line: 1u, col: 4u, msg: @~"invalid number"}); + Err({line: 1u, col: 4u, msg: @~"invalid number"}); - assert from_str(~"3") == ok(num(3f)); - assert from_str(~"3.1") == ok(num(3.1f)); - assert from_str(~"-1.2") == ok(num(-1.2f)); - assert from_str(~"0.4") == ok(num(0.4f)); - assert from_str(~"0.4e5") == ok(num(0.4e5f)); - assert from_str(~"0.4e+15") == ok(num(0.4e15f)); - assert from_str(~"0.4e-01") == ok(num(0.4e-01f)); - assert from_str(~" 3 ") == ok(num(3f)); + assert from_str(~"3") == Ok(num(3f)); + assert from_str(~"3.1") == Ok(num(3.1f)); + assert from_str(~"-1.2") == Ok(num(-1.2f)); + assert from_str(~"0.4") == Ok(num(0.4f)); + assert from_str(~"0.4e5") == Ok(num(0.4e5f)); + assert from_str(~"0.4e+15") == Ok(num(0.4e15f)); + assert from_str(~"0.4e-01") == Ok(num(0.4e-01f)); + assert from_str(~" 3 ") == Ok(num(3f)); } #[test] fn test_read_str() { assert from_str(~"\"") == - err({line: 1u, col: 2u, msg: @~"EOF while parsing string"}); + Err({line: 1u, col: 2u, msg: @~"EOF while parsing string"}); assert from_str(~"\"lol") == - err({line: 1u, col: 5u, msg: @~"EOF while parsing string"}); + Err({line: 1u, col: 5u, msg: @~"EOF while parsing string"}); - assert from_str(~"\"\"") == ok(string(@~"")); - assert from_str(~"\"foo\"") == ok(string(@~"foo")); - assert from_str(~"\"\\\"\"") == ok(string(@~"\"")); - assert from_str(~"\"\\b\"") == ok(string(@~"\x08")); - assert from_str(~"\"\\n\"") == ok(string(@~"\n")); - assert from_str(~"\"\\r\"") == ok(string(@~"\r")); - assert from_str(~"\"\\t\"") == ok(string(@~"\t")); - assert from_str(~" \"foo\" ") == ok(string(@~"foo")); + assert from_str(~"\"\"") == Ok(string(@~"")); + assert from_str(~"\"foo\"") == Ok(string(@~"foo")); + assert from_str(~"\"\\\"\"") == Ok(string(@~"\"")); + assert from_str(~"\"\\b\"") == Ok(string(@~"\x08")); + assert from_str(~"\"\\n\"") == Ok(string(@~"\n")); + assert from_str(~"\"\\r\"") == Ok(string(@~"\r")); + assert from_str(~"\"\\t\"") == Ok(string(@~"\t")); + assert from_str(~" \"foo\" ") == Ok(string(@~"foo")); } #[test] fn test_read_list() { assert from_str(~"[") == - err({line: 1u, col: 2u, msg: @~"EOF while parsing value"}); + Err({line: 1u, col: 2u, msg: @~"EOF while parsing value"}); assert from_str(~"[1") == - err({line: 1u, col: 3u, msg: @~"EOF while parsing list"}); + Err({line: 1u, col: 3u, msg: @~"EOF while parsing list"}); assert from_str(~"[1,") == - err({line: 1u, col: 4u, msg: @~"EOF while parsing value"}); + Err({line: 1u, col: 4u, msg: @~"EOF while parsing value"}); assert from_str(~"[1,]") == - err({line: 1u, col: 4u, msg: @~"invalid syntax"}); + Err({line: 1u, col: 4u, msg: @~"invalid syntax"}); assert from_str(~"[6 7]") == - err({line: 1u, col: 4u, msg: @~"expected `,` or `]`"}); - - assert from_str(~"[]") == ok(list(@~[])); - assert from_str(~"[ ]") == ok(list(@~[])); - assert from_str(~"[true]") == ok(list(@~[boolean(true)])); - assert from_str(~"[ false ]") == ok(list(@~[boolean(false)])); - assert from_str(~"[null]") == ok(list(@~[null])); - assert from_str(~"[3, 1]") == ok(list(@~[num(3f), num(1f)])); - assert from_str(~"\n[3, 2]\n") == ok(list(@~[num(3f), num(2f)])); + Err({line: 1u, col: 4u, msg: @~"expected `,` or `]`"}); + + assert from_str(~"[]") == Ok(list(@~[])); + assert from_str(~"[ ]") == Ok(list(@~[])); + assert from_str(~"[true]") == Ok(list(@~[boolean(true)])); + assert from_str(~"[ false ]") == Ok(list(@~[boolean(false)])); + assert from_str(~"[null]") == Ok(list(@~[null])); + assert from_str(~"[3, 1]") == Ok(list(@~[num(3f), num(1f)])); + assert from_str(~"\n[3, 2]\n") == Ok(list(@~[num(3f), num(2f)])); assert from_str(~"[2, [4, 1]]") == - ok(list(@~[num(2f), list(@~[num(4f), num(1f)])])); + Ok(list(@~[num(2f), list(@~[num(4f), num(1f)])])); } #[test] fn test_read_dict() { assert from_str(~"{") == - err({line: 1u, col: 2u, msg: @~"EOF while parsing object"}); + Err({line: 1u, col: 2u, msg: @~"EOF while parsing object"}); assert from_str(~"{ ") == - err({line: 1u, col: 3u, msg: @~"EOF while parsing object"}); + Err({line: 1u, col: 3u, msg: @~"EOF while parsing object"}); assert from_str(~"{1") == - err({line: 1u, col: 2u, msg: @~"key must be a string"}); + Err({line: 1u, col: 2u, msg: @~"key must be a string"}); assert from_str(~"{ \"a\"") == - err({line: 1u, col: 6u, msg: @~"EOF while parsing object"}); + Err({line: 1u, col: 6u, msg: @~"EOF while parsing object"}); assert from_str(~"{\"a\"") == - err({line: 1u, col: 5u, msg: @~"EOF while parsing object"}); + Err({line: 1u, col: 5u, msg: @~"EOF while parsing object"}); assert from_str(~"{\"a\" ") == - err({line: 1u, col: 6u, msg: @~"EOF while parsing object"}); + Err({line: 1u, col: 6u, msg: @~"EOF while parsing object"}); assert from_str(~"{\"a\" 1") == - err({line: 1u, col: 6u, msg: @~"expected `:`"}); + Err({line: 1u, col: 6u, msg: @~"expected `:`"}); assert from_str(~"{\"a\":") == - err({line: 1u, col: 6u, msg: @~"EOF while parsing value"}); + Err({line: 1u, col: 6u, msg: @~"EOF while parsing value"}); assert from_str(~"{\"a\":1") == - err({line: 1u, col: 7u, msg: @~"EOF while parsing object"}); + Err({line: 1u, col: 7u, msg: @~"EOF while parsing object"}); assert from_str(~"{\"a\":1 1") == - err({line: 1u, col: 8u, msg: @~"expected `,` or `}`"}); + Err({line: 1u, col: 8u, msg: @~"expected `,` or `}`"}); 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(~"{\"a\": 3}")), @@ -879,6 +879,6 @@ mod tests { #[test] fn test_multiline_errors() { assert from_str(~"{\n \"foo\":\n \"bar\"") == - err({line: 3u, col: 8u, msg: @~"EOF while parsing object"}); + Err({line: 3u, col: 8u, msg: @~"EOF while parsing object"}); } } diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index 16598274986..9458aca8db4 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -85,7 +85,7 @@ enum ip_get_addr_err { * object in the case of failure */ fn get_addr(++node: ~str, iotask: iotask) - -> result::result<~[ip_addr], ip_get_addr_err> { + -> result::Result<~[ip_addr], ip_get_addr_err> { do core::comm::listen |output_ch| { do str::as_buf(node) |node_ptr, len| unsafe { log(debug, fmt!("slice len %?", len)); @@ -108,7 +108,7 @@ fn get_addr(++node: ~str, iotask: iotask) set_data_for_req(handle_ptr, handle_data_ptr); } _ => { - output_ch.send(result::err(get_addr_unknown_error)); + output_ch.send(result::Err(get_addr_unknown_error)); } } }; @@ -135,8 +135,8 @@ mod v4 { */ fn parse_addr(ip: ~str) -> ip_addr { match try_parse_addr(ip) { - result::ok(addr) => copy(addr), - result::err(err_data) => fail err_data.err_msg + result::Ok(addr) => copy(addr), + result::Err(err_data) => fail err_data.err_msg } } // the simple, old style numberic representation of @@ -153,7 +153,7 @@ mod v4 { *((ptr::addr_of(self)) as *u32) } } - fn parse_to_ipv4_rep(ip: ~str) -> result::result<ipv4_rep, ~str> { + fn parse_to_ipv4_rep(ip: ~str) -> result::Result<ipv4_rep, ~str> { let parts = vec::map(str::split_char(ip, '.'), |s| { match uint::from_str(s) { Some(n) if n <= 255u => n, @@ -161,23 +161,23 @@ mod v4 { } }); if vec::len(parts) != 4u { - result::err(fmt!("'%s' doesn't have 4 parts", ip)) + result::Err(fmt!("'%s' doesn't have 4 parts", ip)) } else if vec::contains(parts, 256u) { - result::err(fmt!("invalid octal in addr '%s'", ip)) + result::Err(fmt!("invalid octal in addr '%s'", ip)) } else { - result::ok({a: parts[0] as u8, b: parts[1] as u8, + result::Ok({a: parts[0] as u8, b: parts[1] as u8, c: parts[2] as u8, d: parts[3] as u8}) } } - fn try_parse_addr(ip: ~str) -> result::result<ip_addr,parse_addr_err> { + fn try_parse_addr(ip: ~str) -> result::Result<ip_addr,parse_addr_err> { 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); - return result::err({err_msg: err_str}) + return result::Err({err_msg: err_str}) } // ipv4_rep.as_u32 is unsafe :/ let input_is_inaddr_none = @@ -190,15 +190,15 @@ mod v4 { 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); - 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 && !input_is_inaddr_none { - return result::err( + return result::Err( {err_msg: ~"uv_ip4_name produced invalid result."}) } else { - result::ok(ipv4(copy(new_addr))) + result::Ok(ipv4(copy(new_addr))) } } } @@ -221,11 +221,11 @@ mod v6 { */ fn parse_addr(ip: ~str) -> ip_addr { match try_parse_addr(ip) { - result::ok(addr) => copy(addr), - result::err(err_data) => fail err_data.err_msg + result::Ok(addr) => copy(addr), + result::Err(err_data) => fail err_data.err_msg } } - fn try_parse_addr(ip: ~str) -> result::result<ip_addr,parse_addr_err> { + fn try_parse_addr(ip: ~str) -> result::Result<ip_addr,parse_addr_err> { unsafe { // need to figure out how to establish a parse failure.. let new_addr = uv_ip6_addr(ip, 22); @@ -235,18 +235,18 @@ mod v6 { // '::' appears to be uv_ip6_name() returns for bogus // parses.. if ip != ~"::" && reparsed_name == ~"::" { - result::err({err_msg:fmt!("failed to parse '%s'", + result::Err({err_msg:fmt!("failed to parse '%s'", ip)}) } else { - result::ok(ipv6(new_addr)) + result::Ok(ipv6(new_addr)) } } } } type get_addr_data = { - output_ch: comm::Chan<result::result<~[ip_addr],ip_get_addr_err>> + output_ch: comm::Chan<result::Result<~[ip_addr],ip_get_addr_err>> }; extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, @@ -272,7 +272,7 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, log(debug, ~"curr_addr is not of family AF_INET or "+ ~"AF_INET6. Error."); (*handle_data).output_ch.send( - result::err(get_addr_unknown_error)); + result::Err(get_addr_unknown_error)); break; }; out_vec += ~[new_ip_addr]; @@ -289,18 +289,18 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, } log(debug, fmt!("successful process addrinfo result, len: %?", vec::len(out_vec))); - (*handle_data).output_ch.send(result::ok(out_vec)); + (*handle_data).output_ch.send(result::Ok(out_vec)); } else { log(debug, ~"addrinfo pointer is NULL"); (*handle_data).output_ch.send( - result::err(get_addr_unknown_error)); + result::Err(get_addr_unknown_error)); } } else { log(debug, ~"status != 0 error in get_addr_cb"); (*handle_data).output_ch.send( - result::err(get_addr_unknown_error)); + result::Err(get_addr_unknown_error)); } if res != (ptr::null::<addrinfo>()) { uv_freeaddrinfo(res); @@ -327,11 +327,11 @@ mod test { #[test] fn test_ip_ipv4_bad_parse() { match v4::try_parse_addr(~"b4df00d") { - result::err(err_info) => { + result::Err(err_info) => { log(debug, fmt!("got error as expected %?", err_info)); assert true; } - result::ok(addr) => { + result::Ok(addr) => { fail fmt!("Expected failure, but got addr %?", addr); } } @@ -340,11 +340,11 @@ mod test { #[ignore(target_os="win32")] fn test_ip_ipv6_bad_parse() { match v6::try_parse_addr(~"::,~2234k;") { - result::err(err_info) => { + result::Err(err_info) => { log(debug, fmt!("got error as expected %?", err_info)); assert true; } - result::ok(addr) => { + result::Ok(addr) => { fail fmt!("Expected failure, but got addr %?", addr); } } diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 7ffe5b42f9f..07c5319ae3d 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -120,7 +120,7 @@ enum tcp_connect_err_data { */ fn connect(-input_ip: ip::ip_addr, port: uint, iotask: iotask) - -> result::result<tcp_socket, tcp_connect_err_data> unsafe { + -> result::Result<tcp_socket, tcp_connect_err_data> unsafe { let result_po = core::comm::port::<conn_attempt>(); let closed_signal_po = core::comm::port::<()>(); let conn_data = { @@ -128,7 +128,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint, closed_signal_ch: core::comm::chan(closed_signal_po) }; let conn_data_ptr = ptr::addr_of(conn_data); - let reader_po = core::comm::port::<result::result<~[u8], tcp_err_data>>(); + let reader_po = core::comm::port::<result::Result<~[u8], tcp_err_data>>(); let stream_handle_ptr = malloc_uv_tcp_t(); *(stream_handle_ptr as *mut uv::ll::uv_tcp_t) = uv::ll::tcp_t(); let socket_data = @{ @@ -220,7 +220,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint, match core::comm::recv(result_po) { conn_success => { log(debug, ~"tcp::connect - received success on result_po"); - result::ok(tcp_socket(socket_data)) + result::Ok(tcp_socket(socket_data)) } conn_failure(err_data) => { core::comm::recv(closed_signal_po); @@ -232,7 +232,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint, ~"ECONNREFUSED" => connection_refused, _ => generic_connect_err(err_data.err_name, err_data.err_msg) }; - result::err(tcp_conn_err) + result::Err(tcp_conn_err) } } } @@ -252,7 +252,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint, * `tcp_err_data` value as the `err` variant */ fn write(sock: tcp_socket, raw_write_data: ~[u8]) - -> result::result<(), tcp_err_data> unsafe { + -> result::Result<(), tcp_err_data> unsafe { let socket_data_ptr = ptr::addr_of(*(sock.socket_data)); write_common_impl(socket_data_ptr, raw_write_data) } @@ -289,7 +289,7 @@ fn write(sock: tcp_socket, raw_write_data: ~[u8]) * value as the `err` variant */ fn write_future(sock: tcp_socket, raw_write_data: ~[u8]) - -> future::Future<result::result<(), tcp_err_data>> unsafe { + -> future::Future<result::Result<(), tcp_err_data>> unsafe { let socket_data_ptr = ptr::addr_of(*(sock.socket_data)); do future_spawn { let data_copy = copy(raw_write_data); @@ -313,8 +313,8 @@ fn write_future(sock: tcp_socket, raw_write_data: ~[u8]) * `tcp_err_data` record */ fn read_start(sock: tcp_socket) - -> result::result<comm::Port< - result::result<~[u8], tcp_err_data>>, tcp_err_data> unsafe { + -> result::Result<comm::Port< + result::Result<~[u8], tcp_err_data>>, tcp_err_data> unsafe { let socket_data = ptr::addr_of(*(sock.socket_data)); read_start_common_impl(socket_data) } @@ -327,8 +327,8 @@ fn read_start(sock: tcp_socket) * * `sock` - a `net::tcp::tcp_socket` that you wish to stop reading on */ fn read_stop(sock: tcp_socket, - -read_port: comm::Port<result::result<~[u8], tcp_err_data>>) -> - result::result<(), tcp_err_data> unsafe { + -read_port: comm::Port<result::Result<~[u8], tcp_err_data>>) -> + result::Result<(), tcp_err_data> unsafe { log(debug, fmt!("taking the read_port out of commission %?", read_port)); let socket_data = ptr::addr_of(*sock.socket_data); read_stop_common_impl(socket_data) @@ -350,7 +350,7 @@ fn read_stop(sock: tcp_socket, * read attempt. Pass `0u` to wait indefinitely */ fn read(sock: tcp_socket, timeout_msecs: uint) - -> result::result<~[u8],tcp_err_data> { + -> result::Result<~[u8],tcp_err_data> { let socket_data = ptr::addr_of(*(sock.socket_data)); read_common_impl(socket_data, timeout_msecs) } @@ -385,7 +385,7 @@ fn read(sock: tcp_socket, timeout_msecs: uint) * read attempt. Pass `0u` to wait indefinitely */ fn read_future(sock: tcp_socket, timeout_msecs: uint) - -> future::Future<result::result<~[u8],tcp_err_data>> { + -> future::Future<result::Result<~[u8],tcp_err_data>> { let socket_data = ptr::addr_of(*(sock.socket_data)); do future_spawn { read_common_impl(socket_data, timeout_msecs) @@ -462,7 +462,7 @@ fn read_future(sock: tcp_socket, timeout_msecs: uint) * as the `err` variant of a `result`. */ fn accept(new_conn: tcp_new_connection) - -> result::result<tcp_socket, tcp_err_data> unsafe { + -> result::Result<tcp_socket, tcp_err_data> unsafe { match new_conn{ new_tcp_conn(server_handle_ptr) => { @@ -524,8 +524,8 @@ fn accept(new_conn: tcp_new_connection) } // UNSAFE LIBUV INTERACTION END match core::comm::recv(result_po) { - Some(err_data) => result::err(err_data), - None => result::ok(tcp_socket(client_socket_data)) + Some(err_data) => result::Err(err_data), + None => result::Ok(tcp_socket(client_socket_data)) } } } @@ -564,7 +564,7 @@ fn listen(-host_ip: ip::ip_addr, port: uint, backlog: uint, on_establish_cb: fn~(comm::Chan<Option<tcp_err_data>>), +new_connect_cb: fn~(tcp_new_connection, comm::Chan<Option<tcp_err_data>>)) - -> result::result<(), tcp_listen_err_data> unsafe { + -> result::Result<(), tcp_listen_err_data> unsafe { do listen_common(host_ip, port, backlog, iotask, on_establish_cb) // on_connect_cb |handle| unsafe { @@ -580,7 +580,7 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, iotask: iotask, on_establish_cb: fn~(comm::Chan<Option<tcp_err_data>>), -on_connect_cb: fn~(*uv::ll::uv_tcp_t)) - -> result::result<(), tcp_listen_err_data> unsafe { + -> result::Result<(), tcp_listen_err_data> unsafe { let stream_closed_po = core::comm::port::<()>(); let kill_po = core::comm::port::<Option<tcp_err_data>>(); let kill_ch = core::comm::chan(kill_po); @@ -666,16 +666,16 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, match err_data.err_name { ~"EACCES" => { log(debug, ~"Got EACCES error"); - result::err(access_denied) + result::Err(access_denied) } ~"EADDRINUSE" => { log(debug, ~"Got EADDRINUSE error"); - result::err(address_in_use) + result::Err(address_in_use) } _ => { log(debug, fmt!("Got '%s' '%s' libuv error", err_data.err_name, err_data.err_msg)); - result::err( + result::Err( generic_listen_err(err_data.err_name, err_data.err_msg)) } } @@ -692,10 +692,10 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, stream_closed_po.recv(); match kill_result { // some failure post bind/listen - Some(err_data) => result::err(generic_listen_err(err_data.err_name, + Some(err_data) => result::Err(generic_listen_err(err_data.err_name, err_data.err_msg)), // clean exit - None => result::ok(()) + None => result::Ok(()) } } } @@ -722,29 +722,29 @@ fn socket_buf(-sock: tcp_socket) -> tcp_socket_buf { /// Convenience methods extending `net::tcp::tcp_socket` impl tcp_socket { - fn read_start() -> result::result<comm::Port< - result::result<~[u8], tcp_err_data>>, tcp_err_data> { + fn read_start() -> result::Result<comm::Port< + result::Result<~[u8], tcp_err_data>>, tcp_err_data> { read_start(self) } fn read_stop(-read_port: - comm::Port<result::result<~[u8], tcp_err_data>>) -> - result::result<(), tcp_err_data> { + comm::Port<result::Result<~[u8], tcp_err_data>>) -> + result::Result<(), tcp_err_data> { read_stop(self, read_port) } fn read(timeout_msecs: uint) -> - result::result<~[u8], tcp_err_data> { + result::Result<~[u8], tcp_err_data> { read(self, timeout_msecs) } fn read_future(timeout_msecs: uint) -> - future::Future<result::result<~[u8], tcp_err_data>> { + future::Future<result::Result<~[u8], tcp_err_data>> { read_future(self, timeout_msecs) } fn write(raw_write_data: ~[u8]) - -> result::result<(), tcp_err_data> { + -> result::Result<(), tcp_err_data> { write(self, raw_write_data) } fn write_future(raw_write_data: ~[u8]) - -> future::Future<result::result<(), tcp_err_data>> { + -> future::Future<result::Result<(), tcp_err_data>> { write_future(self, raw_write_data) } } @@ -856,13 +856,13 @@ fn tear_down_socket_data(socket_data: @tcp_socket_data) unsafe { // shared implementation for tcp::read fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint) - -> result::result<~[u8],tcp_err_data> unsafe { + -> result::Result<~[u8],tcp_err_data> unsafe { 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); - result::err(err_data) + result::Err(err_data) } else { log(debug, ~"tcp::read before recv_timeout"); @@ -881,7 +881,7 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint) err_msg: ~"req timed out" }; read_stop_common_impl(socket_data); - result::err(err_data) + result::Err(err_data) } Some(data_result) => { log(debug, ~"tcp::read got data"); @@ -894,7 +894,7 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint) // shared impl for read_stop fn read_stop_common_impl(socket_data: *tcp_socket_data) -> - result::result<(), tcp_err_data> unsafe { + result::Result<(), tcp_err_data> unsafe { let stream_handle_ptr = (*socket_data).stream_handle_ptr; let stop_po = core::comm::port::<Option<tcp_err_data>>(); let stop_ch = core::comm::chan(stop_po); @@ -913,15 +913,15 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) -> } }; match core::comm::recv(stop_po) { - Some(err_data) => result::err(err_data.to_tcp_err()), - None => result::ok(()) + Some(err_data) => result::Err(err_data.to_tcp_err()), + None => result::Ok(()) } } // shared impl for read_start fn read_start_common_impl(socket_data: *tcp_socket_data) - -> result::result<comm::Port< - result::result<~[u8], tcp_err_data>>, tcp_err_data> unsafe { + -> result::Result<comm::Port< + result::Result<~[u8], tcp_err_data>>, tcp_err_data> unsafe { let stream_handle_ptr = (*socket_data).stream_handle_ptr; let start_po = core::comm::port::<Option<uv::ll::uv_err_data>>(); let start_ch = core::comm::chan(start_po); @@ -943,8 +943,8 @@ fn read_start_common_impl(socket_data: *tcp_socket_data) } }; match core::comm::recv(start_po) { - Some(err_data) => result::err(err_data.to_tcp_err()), - None => result::ok((*socket_data).reader_po) + Some(err_data) => result::Err(err_data.to_tcp_err()), + None => result::Ok((*socket_data).reader_po) } } @@ -953,7 +953,7 @@ fn read_start_common_impl(socket_data: *tcp_socket_data) // shared implementation used by write and write_future fn write_common_impl(socket_data_ptr: *tcp_socket_data, raw_write_data: ~[u8]) - -> result::result<(), tcp_err_data> unsafe { + -> result::Result<(), tcp_err_data> unsafe { let write_req_ptr = ptr::addr_of((*socket_data_ptr).write_req); let stream_handle_ptr = (*socket_data_ptr).stream_handle_ptr; @@ -989,8 +989,8 @@ fn write_common_impl(socket_data_ptr: *tcp_socket_data, // ownership of everything to the I/O task and let it deal with the // aftermath, so we don't have to sit here blocking. match core::comm::recv(result_po) { - tcp_write_success => result::ok(()), - tcp_write_error(err_data) => result::err(err_data.to_tcp_err()) + tcp_write_success => result::Ok(()), + tcp_write_error(err_data) => result::Err(err_data.to_tcp_err()) } } @@ -1083,7 +1083,7 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t, log(debug, fmt!("on_tcp_read_cb: incoming err.. name %? msg %?", err_data.err_name, err_data.err_msg)); let reader_ch = (*socket_data_ptr).reader_ch; - core::comm::send(reader_ch, result::err(err_data)); + core::comm::send(reader_ch, result::Err(err_data)); } // do nothing .. unneeded buf 0 => (), @@ -1094,7 +1094,7 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t, let reader_ch = (*socket_data_ptr).reader_ch; let buf_base = uv::ll::get_base_from_buf(buf); let new_bytes = vec::unsafe::from_buf(buf_base, nread as uint); - core::comm::send(reader_ch, result::ok(new_bytes)); + core::comm::send(reader_ch, result::Ok(new_bytes)); } } uv::ll::free_base_of_buf(buf); @@ -1197,8 +1197,8 @@ enum conn_attempt { } type tcp_socket_data = { - reader_po: comm::Port<result::result<~[u8], tcp_err_data>>, - reader_ch: comm::Chan<result::result<~[u8], tcp_err_data>>, + reader_po: comm::Port<result::Result<~[u8], tcp_err_data>>, + reader_ch: comm::Chan<result::Result<~[u8], tcp_err_data>>, stream_handle_ptr: *uv::ll::uv_tcp_t, connect_req: uv::ll::uv_connect_t, write_req: uv::ll::uv_write_t, @@ -1515,7 +1515,7 @@ mod test { ~"connection!"); let received_req_bytes = read(sock, 0u); match received_req_bytes { - result::ok(data) => { + result::Ok(data) => { log(debug, ~"SERVER: got REQ str::from_bytes.."); log(debug, fmt!("SERVER: REQ data len: %?", vec::len(data))); @@ -1526,7 +1526,7 @@ mod test { log(debug, ~"SERVER: after write.. die"); core::comm::send(kill_ch, None); } - result::err(err_data) => { + result::Err(err_data) => { log(debug, fmt!("SERVER: error recvd: %s %s", err_data.err_name, err_data.err_msg)); core::comm::send(kill_ch, Some(err_data)); @@ -1585,7 +1585,7 @@ mod test { fn run_tcp_test_client(server_ip: ~str, server_port: uint, resp: ~str, client_ch: comm::Chan<~str>, - iotask: iotask) -> result::result<~str, + iotask: iotask) -> result::Result<~str, tcp_connect_err_data> { let server_ip_addr = ip::v4::parse_addr(server_ip); @@ -1594,7 +1594,7 @@ mod test { if result::is_err(connect_result) { log(debug, ~"CLIENT: failed to connect"); let err_data = result::get_err(connect_result); - err(err_data) + Err(err_data) } else { let sock = result::unwrap(connect_result); @@ -1603,14 +1603,14 @@ mod test { let read_result = sock.read(0u); if read_result.is_err() { log(debug, ~"CLIENT: failure to read"); - ok(~"") + Ok(~"") } else { client_ch.send(str::from_bytes(read_result.get())); let ret_val = client_ch.recv(); log(debug, fmt!("CLIENT: after client_ch recv ret: '%s'", ret_val)); - ok(ret_val) + Ok(ret_val) } } } diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 470a00fb6bc..8e8a7419902 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -330,38 +330,38 @@ fn query_to_str(query: query) -> ~str { } // returns the scheme and the rest of the url, or a parsing error -fn get_scheme(rawurl: ~str) -> result::result<(~str, ~str), @~str> { +fn get_scheme(rawurl: ~str) -> result::Result<(~str, ~str), @~str> { for str::each_chari(rawurl) |i,c| { match c { 'A' to 'Z' | 'a' to 'z' => again, '0' to '9' | '+' | '-' | '.' => { if i == 0 { - return result::err(@~"url: Scheme must begin with a letter."); + return result::Err(@~"url: Scheme must begin with a letter."); } again; } ':' => { if i == 0 { - return result::err(@~"url: Scheme cannot be empty."); + return result::Err(@~"url: Scheme cannot be empty."); } else { - return result::ok((rawurl.slice(0,i), + return result::Ok((rawurl.slice(0,i), rawurl.slice(i+1,str::len(rawurl)))); } } _ => { - return result::err(@~"url: Invalid character in scheme."); + return result::Err(@~"url: Invalid character in scheme."); } } }; - return result::err(@~"url: Scheme must be terminated with a colon."); + return result::Err(@~"url: Scheme must be terminated with a colon."); } // returns userinfo, host, port, and unparsed part, or an error fn get_authority(rawurl: ~str) -> - result::result<(Option<userinfo>, ~str, Option<~str>, ~str), @~str> { + result::Result<(Option<userinfo>, ~str, Option<~str>, ~str), @~str> { if !str::starts_with(rawurl, ~"//") { // there is no authority. - return result::ok((option::None, ~"", option::None, copy rawurl)); + return result::Ok((option::None, ~"", option::None, copy rawurl)); } enum state { @@ -407,7 +407,7 @@ fn get_authority(rawurl: ~str) -> // separators, don't change anything } _ => { - return result::err(@~"Illegal character in authority"); + return result::Err(@~"Illegal character in authority"); } } @@ -423,7 +423,7 @@ fn get_authority(rawurl: ~str) -> pass_host_port => { // multiple colons means ipv6 address. if in == unreserved { - return result::err( + return result::Err( @~"Illegal characters in IPv6 address."); } st = ip6_host; @@ -432,13 +432,13 @@ fn get_authority(rawurl: ~str) -> pos = i; // can't be sure whether this is an ipv6 address or a port if in == unreserved { - return result::err(@~"Illegal characters in authority."); + return result::Err(@~"Illegal characters in authority."); } st = ip6_port; } ip6_port => { if in == unreserved { - return result::err(@~"Illegal characters in authority."); + return result::Err(@~"Illegal characters in authority."); } st = ip6_host; } @@ -450,7 +450,7 @@ fn get_authority(rawurl: ~str) -> } } _ => { - return result::err(@~"Invalid ':' in authority."); + return result::Err(@~"Invalid ':' in authority."); } } in = digit; // reset input class @@ -474,7 +474,7 @@ fn get_authority(rawurl: ~str) -> st = in_host; } _ => { - return result::err(@~"Invalid '@' in authority."); + return result::Err(@~"Invalid '@' in authority."); } } begin = i+1; @@ -507,7 +507,7 @@ fn get_authority(rawurl: ~str) -> } pass_host_port | ip6_port => { if in != digit { - return result::err(@~"Non-digit characters in port."); + return result::Err(@~"Non-digit characters in port."); } host = str::slice(rawurl, begin, pos); port = option::Some(str::slice(rawurl, pos+1, end)); @@ -517,7 +517,7 @@ fn get_authority(rawurl: ~str) -> } in_port => { if in != digit { - return result::err(@~"Non-digit characters in port."); + return result::Err(@~"Non-digit characters in port."); } port = option::Some(str::slice(rawurl, pos+1, end)); } @@ -525,13 +525,13 @@ fn get_authority(rawurl: ~str) -> let rest = if host_is_end_plus_one() { ~"" } else { str::slice(rawurl, end, len) }; - return result::ok((userinfo, host, port, rest)); + return result::Ok((userinfo, host, port, rest)); } // returns the path and unparsed part of url, or an error fn get_path(rawurl: ~str, authority : bool) -> - result::result<(~str, ~str), @~str> { + result::Result<(~str, ~str), @~str> { let len = str::len(rawurl); let mut end = len; for str::each_chari(rawurl) |i,c| { @@ -545,39 +545,39 @@ fn get_path(rawurl: ~str, authority : bool) -> end = i; break; } - _ => return result::err(@~"Invalid character in path.") + _ => return result::Err(@~"Invalid character in path.") } } if authority { if end != 0 && !str::starts_with(rawurl, ~"/") { - return result::err(@~"Non-empty path must begin with\ + return result::Err(@~"Non-empty path must begin with\ '/' in presence of authority."); } } - return result::ok((decode_component(str::slice(rawurl, 0, end)), + return result::Ok((decode_component(str::slice(rawurl, 0, end)), str::slice(rawurl, end, len))); } // returns the parsed query and the fragment, if present fn get_query_fragment(rawurl: ~str) -> - result::result<(query, Option<~str>), @~str> { + result::Result<(query, Option<~str>), @~str> { if !str::starts_with(rawurl, ~"?") { if str::starts_with(rawurl, ~"#") { let f = decode_component(str::slice(rawurl, 1, str::len(rawurl))); - return result::ok((~[], option::Some(f))); + return result::Ok((~[], option::Some(f))); } else { - return result::ok((~[], option::None)); + return result::Ok((~[], option::None)); } } let (q, r) = split_char_first(str::slice(rawurl, 1, str::len(rawurl)), '#'); let f = if str::len(r) != 0 { option::Some(decode_component(r)) } else { option::None }; - return result::ok((query_from_str(q), f)); + return result::Ok((query_from_str(q), f)); } /** @@ -593,18 +593,18 @@ 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 let mut schm = get_scheme(rawurl); 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); // authority let mut auth = get_authority(rest); 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); @@ -612,18 +612,18 @@ fn from_str(rawurl: ~str) -> result::result<url, ~str> { 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)); + 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)); + return result::Err(copy *result::get_err(qry)); } let (query, fragment) = result::unwrap(qry); - return result::ok(url(scheme, userinfo, host, + return result::Ok(url(scheme, userinfo, host, port, path, query, fragment)); } diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 01bb89556c8..a1416177a6a 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -855,7 +855,7 @@ mod tests { let m = ~mutex(); let m2 = ~m.clone(); - let result: result::result<(),()> = do task::try { + let result: result::Result<(),()> = do task::try { do m2.lock { fail; } @@ -871,7 +871,7 @@ mod tests { let m = ~mutex(); let m2 = ~m.clone(); - let result: result::result<(),()> = do task::try { + let result: result::Result<(),()> = do task::try { let (c,p) = pipes::stream(); do task::spawn { // linked let _ = p.recv(); // wait for sibling to get in the mutex @@ -896,7 +896,7 @@ mod tests { let m2 = ~m.clone(); let (c,p) = pipes::stream(); - let result: result::result<(),()> = do task::try { + let result: result::Result<(),()> = do task::try { let mut sibling_convos = ~[]; for 2.times { let (c,p) = pipes::stream(); @@ -1196,7 +1196,7 @@ mod tests { let x = ~rwlock(); let x2 = ~x.clone(); - let result: result::result<(),()> = do task::try { + let result: result::Result<(),()> = do task::try { do lock_rwlock_in_mode(x2, mode1) { fail; } diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 803916f64a1..46ad1a95dc3 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -6,7 +6,7 @@ // while providing a base that other test frameworks may build off of. import either::Either; -import result::{ok, err}; +import result::{Ok, Err}; import io::WriterUtil; import libc::size_t; import task::TaskBuilder; @@ -71,8 +71,8 @@ fn parse_opts(args: ~[~str]) -> opt_res { let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")]; let matches = match getopts::getopts(args_, opts) { - ok(m) => m, - err(f) => return either::Right(getopts::fail_str(f)) + Ok(m) => m, + Err(f) => return either::Right(getopts::fail_str(f)) }; let filter = @@ -143,8 +143,8 @@ fn run_tests_console(opts: test_opts, let log_out = match opts.logfile { Some(path) => match io::file_writer(&Path(path), ~[io::Create, io::Truncate]) { - result::ok(w) => Some(w), - result::err(s) => { + result::Ok(w) => Some(w), + result::Err(s) => { fail(fmt!("can't open output file: %s", s)) } }, diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 20137289447..174f92a3486 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -3,7 +3,7 @@ import libc::{c_char, c_int, c_long, size_t, time_t}; import io::Reader; -import result::{result, ok, err}; +import result::{Result, Ok, Err}; export timespec, @@ -131,7 +131,7 @@ fn now() -> tm { } /// Parses the time from the string according to the format string. -fn strptime(s: &str, format: &str) -> result<tm, ~str> { +fn strptime(s: &str, format: &str) -> Result<tm, ~str> { type tm_mut = { mut tm_sec: i32, mut tm_min: i32, @@ -197,20 +197,20 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { Some((value, pos)) } - fn parse_char(s: &str, pos: uint, c: char) -> result<uint, ~str> { + fn parse_char(s: &str, pos: uint, c: char) -> Result<uint, ~str> { let {ch, next} = str::char_range_at(s, pos); if c == ch { - ok(next) + Ok(next) } else { - err(fmt!("Expected %?, found %?", + Err(fmt!("Expected %?, found %?", str::from_char(c), str::from_char(ch))) } } fn parse_type(s: &str, pos: uint, ch: char, tm: &tm_mut) - -> result<uint, ~str> { + -> Result<uint, ~str> { match ch { 'A' => match match_strs(s, pos, ~[ (~"Sunday", 0_i32), @@ -221,8 +221,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { (~"Friday", 5_i32), (~"Saturday", 6_i32) ]) { - Some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } - None => err(~"Invalid day") + Some(item) => { let (v, pos) = item; tm.tm_wday = v; Ok(pos) } + None => Err(~"Invalid day") }, 'a' => match match_strs(s, pos, ~[ (~"Sun", 0_i32), @@ -233,8 +233,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { (~"Fri", 5_i32), (~"Sat", 6_i32) ]) { - Some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } - None => err(~"Invalid day") + Some(item) => { let (v, pos) = item; tm.tm_wday = v; Ok(pos) } + None => Err(~"Invalid day") }, 'B' => match match_strs(s, pos, ~[ (~"January", 0_i32), @@ -250,8 +250,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { (~"November", 10_i32), (~"December", 11_i32) ]) { - Some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) } - None => err(~"Invalid month") + Some(item) => { let (v, pos) = item; tm.tm_mon = v; Ok(pos) } + None => Err(~"Invalid month") }, 'b' | 'h' => match match_strs(s, pos, ~[ (~"Jan", 0_i32), @@ -267,16 +267,16 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { (~"Nov", 10_i32), (~"Dec", 11_i32) ]) { - Some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) } - None => err(~"Invalid month") + Some(item) => { let (v, pos) = item; tm.tm_mon = v; Ok(pos) } + None => Err(~"Invalid month") }, 'C' => match match_digits(s, pos, 2u, false) { Some(item) => { let (v, pos) = item; tm.tm_year += (v * 100_i32) - 1900_i32; - ok(pos) + Ok(pos) } - None => err(~"Invalid year") + None => Err(~"Invalid year") }, 'c' => { parse_type(s, pos, 'a', tm) @@ -297,12 +297,12 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { .chain(|pos| parse_type(s, pos, 'y', tm)) } 'd' => match match_digits(s, pos, 2u, false) { - Some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) } - None => err(~"Invalid day of the month") + Some(item) => { let (v, pos) = item; tm.tm_mday = v; Ok(pos) } + None => Err(~"Invalid day of the month") }, 'e' => match match_digits(s, pos, 2u, true) { - Some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) } - None => err(~"Invalid day of the month") + Some(item) => { let (v, pos) = item; tm.tm_mday = v; Ok(pos) } + None => Err(~"Invalid day of the month") }, 'F' => { parse_type(s, pos, 'Y', tm) @@ -314,8 +314,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { 'H' => { // FIXME (#2350): range check. match match_digits(s, pos, 2u, false) { - Some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) } - None => err(~"Invalid hour") + Some(item) => { let (v, pos) = item; tm.tm_hour = v; Ok(pos) } + None => Err(~"Invalid hour") } } 'I' => { @@ -324,9 +324,9 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { Some(item) => { let (v, pos) = item; tm.tm_hour = if v == 12_i32 { 0_i32 } else { v }; - ok(pos) + Ok(pos) } - None => err(~"Invalid hour") + None => Err(~"Invalid hour") } } 'j' => { @@ -335,16 +335,16 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { Some(item) => { let (v, pos) = item; tm.tm_yday = v - 1_i32; - ok(pos) + Ok(pos) } - None => err(~"Invalid year") + None => Err(~"Invalid year") } } 'k' => { // FIXME (#2350): range check. match match_digits(s, pos, 2u, true) { - Some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) } - None => err(~"Invalid hour") + Some(item) => { let (v, pos) = item; tm.tm_hour = v; Ok(pos) } + None => Err(~"Invalid hour") } } 'l' => { @@ -353,16 +353,16 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { Some(item) => { let (v, pos) = item; tm.tm_hour = if v == 12_i32 { 0_i32 } else { v }; - ok(pos) + Ok(pos) } - None => err(~"Invalid hour") + None => Err(~"Invalid hour") } } 'M' => { // FIXME (#2350): range check. match match_digits(s, pos, 2u, false) { - Some(item) => { let (v, pos) = item; tm.tm_min = v; ok(pos) } - None => err(~"Invalid minute") + Some(item) => { let (v, pos) = item; tm.tm_min = v; Ok(pos) } + None => Err(~"Invalid minute") } } 'm' => { @@ -371,23 +371,23 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { Some(item) => { let (v, pos) = item; tm.tm_mon = v - 1_i32; - ok(pos) + Ok(pos) } - None => err(~"Invalid month") + None => Err(~"Invalid month") } } 'n' => parse_char(s, pos, '\n'), 'P' => match match_strs(s, pos, ~[(~"am", 0_i32), (~"pm", 12_i32)]) { - Some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) } - None => err(~"Invalid hour") + Some(item) => { let (v, pos) = item; tm.tm_hour += v; Ok(pos) } + None => Err(~"Invalid hour") }, 'p' => match match_strs(s, pos, ~[(~"AM", 0_i32), (~"PM", 12_i32)]) { - Some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) } - None => err(~"Invalid hour") + Some(item) => { let (v, pos) = item; tm.tm_hour += v; Ok(pos) } + None => Err(~"Invalid hour") }, 'R' => { parse_type(s, pos, 'H', tm) @@ -409,9 +409,9 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { Some(item) => { let (v, pos) = item; tm.tm_sec = v; - ok(pos) + Ok(pos) } - None => err(~"Invalid second") + None => Err(~"Invalid second") } } //'s' {} @@ -429,9 +429,9 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { Some(item) => { let (v, pos) = item; tm.tm_wday = v; - ok(pos) + Ok(pos) } - None => err(~"Invalid weekday") + None => Err(~"Invalid weekday") } } 'v' => { @@ -445,8 +445,8 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { 'w' => { // FIXME (#2350): range check. match match_digits(s, pos, 1u, false) { - Some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) } - None => err(~"Invalid weekday") + Some(item) => { let (v, pos) = item; tm.tm_wday = v; Ok(pos) } + None => Err(~"Invalid weekday") } } //'X' {} @@ -457,9 +457,9 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { Some(item) => { let (v, pos) = item; tm.tm_year = v - 1900_i32; - ok(pos) + Ok(pos) } - None => err(~"Invalid weekday") + None => Err(~"Invalid weekday") } } 'y' => { @@ -468,16 +468,16 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { Some(item) => { let (v, pos) = item; tm.tm_year = v - 1900_i32; - ok(pos) + Ok(pos) } - None => err(~"Invalid weekday") + None => Err(~"Invalid weekday") } } 'Z' => { if match_str(s, pos, ~"UTC") || match_str(s, pos, ~"GMT") { tm.tm_gmtoff = 0_i32; tm.tm_zone = ~"UTC"; - ok(pos + 3u) + Ok(pos + 3u) } else { // It's odd, but to maintain compatibility with c's // strptime we ignore the timezone. @@ -489,7 +489,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { if ch == ' ' { break; } } - ok(pos) + Ok(pos) } } 'z' => { @@ -504,17 +504,17 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { tm.tm_zone = ~"UTC"; } - ok(pos) + Ok(pos) } - None => err(~"Invalid zone offset") + None => Err(~"Invalid zone offset") } } else { - err(~"Invalid zone offset") + Err(~"Invalid zone offset") } } '%' => parse_char(s, pos, '%'), ch => { - err(fmt!("unknown formatting type: %?", str::from_char(ch))) + Err(fmt!("unknown formatting type: %?", str::from_char(ch))) } } } @@ -536,15 +536,15 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { }; let mut pos = 0u; let len = str::len(s); - let mut result = err(~"Invalid time"); + let mut result = Err(~"Invalid time"); while !rdr.eof() && pos < len { let {ch, next} = str::char_range_at(s, pos); match rdr.read_char() { '%' => match parse_type(s, pos, rdr.read_char(), &tm) { - ok(next) => pos = next, - err(e) => { result = err(e); break; } + Ok(next) => pos = next, + Err(e) => { result = Err(e); break; } }, c => { if c != ch { break } @@ -554,7 +554,7 @@ fn strptime(s: &str, format: &str) -> result<tm, ~str> { } if pos == len && rdr.eof() { - ok(tm_({ + Ok(tm_({ tm_sec: tm.tm_sec, tm_min: tm.tm_min, tm_hour: tm.tm_hour, @@ -947,7 +947,7 @@ mod tests { tzset(); match strptime(~"", ~"") { - ok(tm) => { + Ok(tm) => { assert tm.tm_sec == 0_i32; assert tm.tm_min == 0_i32; assert tm.tm_hour == 0_i32; @@ -960,17 +960,17 @@ mod tests { assert tm.tm_zone == ~""; assert tm.tm_nsec == 0_i32; } - err(_) => () + Err(_) => () } let format = ~"%a %b %e %T %Y"; - assert strptime(~"", format) == err(~"Invalid time"); + assert strptime(~"", format) == Err(~"Invalid time"); assert strptime(~"Fri Feb 13 15:31:30", format) - == err(~"Invalid time"); + == Err(~"Invalid time"); match strptime(~"Fri Feb 13 15:31:30 2009", format) { - err(e) => fail e, - ok(tm) => { + Err(e) => fail e, + Ok(tm) => { assert tm.tm_sec == 30_i32; assert tm.tm_min == 31_i32; assert tm.tm_hour == 15_i32; @@ -988,8 +988,8 @@ mod tests { fn test(s: &str, format: &str) -> bool { match strptime(s, format) { - ok(tm) => tm.strftime(format) == str::from_slice(s), - err(e) => fail e + Ok(tm) => tm.strftime(format) == str::from_slice(s), + Err(e) => fail e } } |
