summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-08-26 16:54:31 -0700
committerBrian Anderson <banderson@mozilla.com>2012-08-27 14:37:04 -0700
commit0c6e470a257fc546555aa10ededded4a77460a71 (patch)
treefb54281612401dba521efedab7626474c80195a9 /src/libcore
parent3a1582012eafb8b672e15b12b5424e72ea6096af (diff)
downloadrust-0c6e470a257fc546555aa10ededded4a77460a71.tar.gz
rust-0c6e470a257fc546555aa10ededded4a77460a71.zip
Convert core::result to camel case
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/either.rs8
-rw-r--r--src/libcore/io.rs46
-rw-r--r--src/libcore/result.rs178
-rw-r--r--src/libcore/task.rs16
4 files changed, 124 insertions, 124 deletions
diff --git a/src/libcore/either.rs b/src/libcore/either.rs
index cd863c168f6..d1dbfecb555 100644
--- a/src/libcore/either.rs
+++ b/src/libcore/either.rs
@@ -4,7 +4,7 @@
 
 //! A type that represents one of two alternatives
 
-import result::result;
+import result::Result;
 
 /// The either type
 enum Either<T, U> {
@@ -83,7 +83,7 @@ pure fn flip<T: copy, U: copy>(eith: &Either<T, U>) -> Either<U, T> {
     }
 }
 
-pure fn to_result<T: copy, U: copy>(eith: &Either<T, U>) -> result<U, T> {
+pure fn to_result<T: copy, U: copy>(eith: &Either<T, U>) -> Result<U, T> {
     /*!
      * Converts either::t to a result::t
      *
@@ -92,8 +92,8 @@ pure fn to_result<T: copy, U: copy>(eith: &Either<T, U>) -> result<U, T> {
      */
 
     match *eith {
-      Right(r) => result::ok(r),
-      Left(l) => result::err(l)
+      Right(r) => result::Ok(r),
+      Left(l) => result::Err(l)
     }
 }
 
diff --git a/src/libcore/io.rs b/src/libcore/io.rs
index 71d8129b035..dd98e471d7d 100644
--- a/src/libcore/io.rs
+++ b/src/libcore/io.rs
@@ -4,7 +4,7 @@ Module: io
 Basic input/output
 */
 
-import result::result;
+import result::Result;
 
 import dvec::{DVec, dvec};
 import libc::{c_int, c_long, c_uint, c_void, size_t, ssize_t};
@@ -264,16 +264,16 @@ fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader {
 
 fn stdin() -> Reader { rustrt::rust_get_stdin() as Reader }
 
-fn file_reader(path: &Path) -> result<Reader, ~str> {
+fn file_reader(path: &Path) -> Result<Reader, ~str> {
     let f = os::as_c_charp(path.to_str(), |pathbuf| {
         os::as_c_charp("r", |modebuf|
             libc::fopen(pathbuf, modebuf)
         )
     });
-    return if f as uint == 0u { result::err(~"error opening "
+    return if f as uint == 0u { result::Err(~"error opening "
                                             + path.to_str()) }
     else {
-        result::ok(FILE_reader(f, true))
+        result::Ok(FILE_reader(f, true))
     }
 }
 
@@ -421,7 +421,7 @@ fn fd_writer(fd: fd_t, cleanup: bool) -> Writer {
 
 
 fn mk_file_writer(path: &Path, flags: ~[FileFlag])
-    -> result<Writer, ~str> {
+    -> Result<Writer, ~str> {
 
     #[cfg(windows)]
     fn wb() -> c_int { (O_WRONLY | O_BINARY) as c_int }
@@ -443,10 +443,10 @@ fn mk_file_writer(path: &Path, flags: ~[FileFlag])
                    (S_IRUSR | S_IWUSR) as c_int)
     };
     if fd < (0 as c_int) {
-        result::err(fmt!("error opening %s: %s", path.to_str(),
+        result::Err(fmt!("error opening %s: %s", path.to_str(),
                          os::last_os_error()))
     } else {
-        result::ok(fd_writer(fd, true))
+        result::Ok(fd_writer(fd, true))
     }
 }
 
@@ -623,21 +623,21 @@ impl<T: Writer> T : WriterUtil {
     fn write_u8(n: u8) { self.write(&[n]) }
 }
 
-fn file_writer(path: &Path, flags: ~[FileFlag]) -> result<Writer, ~str> {
-    result::chain(mk_file_writer(path, flags), |w| result::ok(w))
+fn file_writer(path: &Path, flags: ~[FileFlag]) -> Result<Writer, ~str> {
+    result::chain(mk_file_writer(path, flags), |w| result::Ok(w))
 }
 
 
 // FIXME: fileflags // #2004
-fn buffered_file_writer(path: &Path) -> result<Writer, ~str> {
+fn buffered_file_writer(path: &Path) -> Result<Writer, ~str> {
     let f = do os::as_c_charp(path.to_str()) |pathbuf| {
         do os::as_c_charp("w") |modebuf| {
             libc::fopen(pathbuf, modebuf)
         }
     };
-    return if f as uint == 0u { result::err(~"error opening "
+    return if f as uint == 0u { result::Err(~"error opening "
                                             + path.to_str()) }
-    else { result::ok(FILE_writer(f, true)) }
+    else { result::Ok(FILE_writer(f, true)) }
 }
 
 // FIXME (#2004) it would be great if this could be a const
@@ -719,21 +719,21 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
     return bpos as uint;
 }
 
-fn read_whole_file_str(file: &Path) -> result<~str, ~str> {
+fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
     result::chain(read_whole_file(file), |bytes| {
         if str::is_utf8(bytes) {
-            result::ok(str::from_bytes(bytes))
+            result::Ok(str::from_bytes(bytes))
        } else {
-           result::err(file.to_str() + ~" is not UTF-8")
+           result::Err(file.to_str() + ~" is not UTF-8")
        }
     })
 }
 
 // FIXME (#2004): implement this in a low-level way. Going through the
 // abstractions is pointless.
-fn read_whole_file(file: &Path) -> result<~[u8], ~str> {
+fn read_whole_file(file: &Path) -> Result<~[u8], ~str> {
     result::chain(file_reader(file), |rdr| {
-        result::ok(rdr.read_whole_stream())
+        result::Ok(rdr.read_whole_stream())
     })
 }
 
@@ -892,30 +892,30 @@ mod tests {
     #[test]
     fn file_reader_not_exist() {
         match io::file_reader(&Path("not a file")) {
-          result::err(e) => {
+          result::Err(e) => {
             assert e == ~"error opening not a file";
           }
-          result::ok(_) => fail
+          result::Ok(_) => fail
         }
     }
 
     #[test]
     fn file_writer_bad_name() {
         match io::file_writer(&Path("?/?"), ~[]) {
-          result::err(e) => {
+          result::Err(e) => {
             assert str::starts_with(e, "error opening");
           }
-          result::ok(_) => fail
+          result::Ok(_) => fail
         }
     }
 
     #[test]
     fn buffered_file_writer_bad_name() {
         match io::buffered_file_writer(&Path("?/?")) {
-          result::err(e) => {
+          result::Err(e) => {
             assert str::starts_with(e, "error opening");
           }
-          result::ok(_) => fail
+          result::Ok(_) => fail
         }
     }
 
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index 2afbd833dcf..e39ce87264e 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -3,11 +3,11 @@
 import either::Either;
 
 /// The result type
-enum result<T, U> {
+enum Result<T, U> {
     /// Contains the successful result value
-    ok(T),
+    Ok(T),
     /// Contains the error value
-    err(U)
+    Err(U)
 }
 
 /**
@@ -17,10 +17,10 @@ enum result<T, U> {
  *
  * If the result is an error
  */
-pure fn get<T: copy, U>(res: result<T, U>) -> T {
+pure fn get<T: copy, U>(res: Result<T, U>) -> T {
     match res {
-      ok(t) => t,
-      err(the_err) => unchecked {
+      Ok(t) => t,
+      Err(the_err) => unchecked {
         fail fmt!("get called on error result: %?", the_err)
       }
     }
@@ -33,10 +33,10 @@ pure fn get<T: copy, U>(res: result<T, U>) -> T {
  *
  * If the result is an error
  */
-pure fn get_ref<T, U>(res: &a/result<T, U>) -> &a/T {
+pure fn get_ref<T, U>(res: &a/Result<T, U>) -> &a/T {
     match *res {
-        ok(ref t) => t,
-        err(ref the_err) => unchecked {
+        Ok(ref t) => t,
+        Err(ref the_err) => unchecked {
             fail fmt!("get_ref called on error result: %?", the_err)
         }
     }
@@ -49,23 +49,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 {
+pure fn get_err<T, U: copy>(res: Result<T, U>) -> U {
     match res {
-      err(u) => u,
-      ok(_) => fail ~"get_error called on ok result"
+      Err(u) => u,
+      Ok(_) => fail ~"get_error called on ok result"
     }
 }
 
 /// Returns true if the result is `ok`
-pure fn is_ok<T, U>(res: result<T, U>) -> bool {
+pure fn is_ok<T, U>(res: Result<T, U>) -> bool {
     match res {
-      ok(_) => true,
-      err(_) => false
+      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)
 }
 
@@ -75,10 +75,10 @@ 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> {
+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_)
+      Ok(res) => either::Right(res),
+      Err(fail_) => either::Left(fail_)
     }
 }
 
@@ -96,11 +96,11 @@ pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> Either<T, U> {
  *         ok(parse_buf(buf))
  *     }
  */
-fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>)
-    -> result<U, V> {
+fn chain<T, U: copy, V: copy>(res: Result<T, V>, op: fn(T) -> Result<U, V>)
+    -> Result<U, V> {
     match res {
-      ok(t) => op(t),
-      err(e) => err(e)
+      Ok(t) => op(t),
+      Err(e) => Err(e)
     }
 }
 
@@ -113,12 +113,12 @@ 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>)
-    -> result<T, U> {
+    res: Result<T, V>,
+    op: fn(V) -> Result<T, U>)
+    -> Result<T, U> {
     match res {
-      ok(t) => ok(t),
-      err(v) => op(v)
+      Ok(t) => Ok(t),
+      Err(v) => op(v)
     }
 }
 
@@ -136,10 +136,10 @@ fn chain_err<T: copy, U: copy, V: copy>(
  *         print_buf(buf)
  *     }
  */
-fn iter<T, E>(res: result<T, E>, f: fn(T)) {
+fn iter<T, E>(res: Result<T, E>, f: fn(T)) {
     match res {
-      ok(t) => f(t),
-      err(_) => ()
+      Ok(t) => f(t),
+      Err(_) => ()
     }
 }
 
@@ -151,10 +151,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)) {
+fn iter_err<T, E>(res: Result<T, E>, f: fn(E)) {
     match res {
-      ok(_) => (),
-      err(e) => f(e)
+      Ok(_) => (),
+      Err(e) => f(e)
     }
 }
 
@@ -172,11 +172,11 @@ fn iter_err<T, E>(res: result<T, E>, f: fn(E)) {
  *         parse_buf(buf)
  *     }
  */
-fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U)
-  -> result<U, E> {
+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)),
-      err(e) => err(e)
+      Ok(t) => Ok(op(t)),
+      Err(e) => Err(e)
     }
 }
 
@@ -188,62 +188,62 @@ 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)
-  -> result<T, F> {
+fn map_err<T: copy, E, F: copy>(res: Result<T, E>, op: fn(E) -> F)
+  -> Result<T, F> {
     match res {
-      ok(t) => ok(t),
-      err(e) => err(op(e))
+      Ok(t) => Ok(t),
+      Err(e) => Err(op(e))
     }
 }
 
-impl<T, E> result<T, E> {
+impl<T, E> Result<T, E> {
     fn is_ok() -> bool { is_ok(self) }
 
     fn is_err() -> bool { is_err(self) }
 
     fn iter(f: fn(T)) {
         match self {
-          ok(t) => f(t),
-          err(_) => ()
+          Ok(t) => f(t),
+          Err(_) => ()
         }
     }
 
     fn iter_err(f: fn(E)) {
         match self {
-          ok(_) => (),
-          err(e) => f(e)
+          Ok(_) => (),
+          Err(e) => f(e)
         }
     }
 }
 
-impl<T: copy, E> result<T, E> {
+impl<T: copy, E> Result<T, E> {
     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))
+          Ok(t) => Ok(t),
+          Err(e) => Err(op(e))
         }
     }
 }
 
-impl<T, E: copy> result<T, E> {
+impl<T, E: copy> Result<T, E> {
     fn get_err() -> E { get_err(self) }
 
-    fn 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)),
-          err(e) => err(e)
+          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> {
+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_err<F:copy>(op: fn(E) -> result<T,F>) -> result<T,F> {
+    fn chain_err<F:copy>(op: fn(E) -> Result<T,F>) -> Result<T,F> {
         chain_err(self, op)
     }
 }
@@ -266,27 +266,27 @@ impl<T: copy, E: copy> result<T, E> {
  *     }
  */
 fn map_vec<T,U:copy,V:copy>(
-    ts: &[T], op: fn(T) -> result<V,U>) -> result<~[V],U> {
+    ts: &[T], op: fn(T) -> Result<V,U>) -> Result<~[V],U> {
 
     let mut vs: ~[V] = ~[];
     vec::reserve(vs, vec::len(ts));
     for vec::each(ts) |t| {
         match op(t) {
-          ok(v) => vec::push(vs, v),
-          err(u) => return err(u)
+          Ok(v) => vec::push(vs, v),
+          Err(u) => return Err(u)
         }
     }
-    return ok(vs);
+    return Ok(vs);
 }
 
 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 {
-      None => ok(None),
+      None => Ok(None),
       Some(t) => match op(t) {
-        ok(v) => ok(Some(v)),
-        err(e) => err(e)
+        Ok(v) => Ok(Some(v)),
+        Err(e) => Err(e)
       }
     }
 }
@@ -301,7 +301,7 @@ 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);
@@ -310,12 +310,12 @@ fn map_vec2<S,T,U:copy,V:copy>(ss: &[S], ts: &[T],
     let mut i = 0u;
     while i < n {
         match op(ss[i],ts[i]) {
-          ok(v) => vec::push(vs, v),
-          err(u) => return err(u)
+          Ok(v) => vec::push(vs, v),
+          Err(u) => return Err(u)
         }
         i += 1u;
     }
-    return ok(vs);
+    return Ok(vs);
 }
 
 /**
@@ -324,27 +324,27 @@ 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]) {
-          ok(()) => (),
-          err(u) => return err(u)
+          Ok(()) => (),
+          Err(u) => return Err(u)
         }
         i += 1u;
     }
-    return ok(());
+    return Ok(());
 }
 
 /// Unwraps a result, assuming it is an `ok(T)`
-fn unwrap<T, U>(-res: result<T, U>) -> T {
+fn unwrap<T, U>(-res: Result<T, U>) -> T {
     unsafe {
         let addr = match res {
-          ok(x) => ptr::addr_of(x),
-          err(_) => fail ~"error result"
+          Ok(x) => ptr::addr_of(x),
+          Err(_) => fail ~"error result"
         };
         let liberated_value = unsafe::reinterpret_cast(*addr);
         unsafe::forget(res);
@@ -354,13 +354,13 @@ fn unwrap<T, U>(-res: result<T, U>) -> T {
 
 #[cfg(test)]
 mod tests {
-    fn op1() -> result::result<int, ~str> { result::ok(666) }
+    fn op1() -> result::Result<int, ~str> { result::Ok(666) }
 
-    fn op2(&&i: int) -> result::result<uint, ~str> {
-        result::ok(i as uint + 1u)
+    fn op2(&&i: int) -> result::Result<uint, ~str> {
+        result::Ok(i as uint + 1u)
     }
 
-    fn op3() -> result::result<int, ~str> { result::err(~"sadface") }
+    fn op3() -> result::Result<int, ~str> { result::Err(~"sadface") }
 
     #[test]
     fn chain_success() {
@@ -375,33 +375,33 @@ mod tests {
     #[test]
     fn test_impl_iter() {
         let mut valid = false;
-        ok::<~str, ~str>(~"a").iter(|_x| valid = true);
+        Ok::<~str, ~str>(~"a").iter(|_x| valid = true);
         assert valid;
 
-        err::<~str, ~str>(~"b").iter(|_x| valid = false);
+        Err::<~str, ~str>(~"b").iter(|_x| valid = false);
         assert valid;
     }
 
     #[test]
     fn test_impl_iter_err() {
         let mut valid = true;
-        ok::<~str, ~str>(~"a").iter_err(|_x| valid = false);
+        Ok::<~str, ~str>(~"a").iter_err(|_x| valid = false);
         assert valid;
 
         valid = false;
-        err::<~str, ~str>(~"b").iter_err(|_x| valid = true);
+        Err::<~str, ~str>(~"b").iter_err(|_x| valid = true);
         assert valid;
     }
 
     #[test]
     fn test_impl_map() {
-        assert ok::<~str, ~str>(~"a").map(|_x| ~"b") == ok(~"b");
-        assert err::<~str, ~str>(~"a").map(|_x| ~"b") == err(~"a");
+        assert Ok::<~str, ~str>(~"a").map(|_x| ~"b") == Ok(~"b");
+        assert Err::<~str, ~str>(~"a").map(|_x| ~"b") == Err(~"a");
     }
 
     #[test]
     fn test_impl_map_err() {
-        assert ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == ok(~"a");
-        assert err::<~str, ~str>(~"a").map_err(|_x| ~"b") == err(~"b");
+        assert Ok::<~str, ~str>(~"a").map_err(|_x| ~"b") == Ok(~"a");
+        assert Err::<~str, ~str>(~"a").map_err(|_x| ~"b") == Err(~"b");
     }
 }
diff --git a/src/libcore/task.rs b/src/libcore/task.rs
index 2699c0d3b3d..8b4b078d5f5 100644
--- a/src/libcore/task.rs
+++ b/src/libcore/task.rs
@@ -27,7 +27,7 @@
  * ~~~
  */
 
-import result::result;
+import result::Result;
 
 export Task;
 export TaskResult;
@@ -406,7 +406,7 @@ impl TaskBuilder {
      * # Failure
      * Fails if a future_result was already set for this task.
      */
-    fn try<T: send>(+f: fn~() -> T) -> result<T,()> {
+    fn try<T: send>(+f: fn~() -> T) -> Result<T,()> {
         let po = comm::port();
         let ch = comm::chan(po);
         let mut result = None;
@@ -415,8 +415,8 @@ impl TaskBuilder {
             comm::send(ch, f());
         }
         match future::get(&option::unwrap(result)) {
-            Success => result::ok(comm::recv(po)),
-            Failure => result::err(())
+            Success => result::Ok(comm::recv(po)),
+            Failure => result::Err(())
         }
     }
 }
@@ -526,7 +526,7 @@ fn spawn_sched(mode: SchedMode, +f: fn~()) {
     task().sched_mode(mode).spawn(f)
 }
 
-fn try<T:send>(+f: fn~() -> T) -> result<T,()> {
+fn try<T:send>(+f: fn~() -> T) -> Result<T,()> {
     /*!
      * Execute a function in another task and return either the return value
      * of the function or result::err.
@@ -1769,7 +1769,7 @@ fn test_try_success() {
     match do try {
         ~"Success!"
     } {
-        result::ok(~"Success!") => (),
+        result::Ok(~"Success!") => (),
         _ => fail
     }
 }
@@ -1780,8 +1780,8 @@ fn test_try_fail() {
     match do try {
         fail
     } {
-        result::err(()) => (),
-        result::ok(()) => fail
+        result::Err(()) => (),
+        result::Ok(()) => fail
     }
 }