about summary refs log tree commit diff
path: root/src/libextra
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-09-14 08:50:50 -0700
committerbors <bors@rust-lang.org>2013-09-14 08:50:50 -0700
commit1c26513ef9a58fa3e6703320cc37427aa229bbbd (patch)
tree2d769c50c2a442c6f3fd0773fa5106ba51af10f6 /src/libextra
parent5d905f1314d243eb1572588f7e7e98768f8bb711 (diff)
parent15c9dc7a86d14f4aba3e23f91af65671aa4b5001 (diff)
downloadrust-1c26513ef9a58fa3e6703320cc37427aa229bbbd.tar.gz
rust-1c26513ef9a58fa3e6703320cc37427aa229bbbd.zip
auto merge of #9180 : blake2-ppc/rust/reduce-either, r=catamorphism
Work a bit towards #9157 "Remove Either". These instances don't need to use Either and are better expressed in other ways (removing allocations and simplifying types).
Diffstat (limited to 'src/libextra')
-rw-r--r--src/libextra/test.rs20
-rw-r--r--src/libextra/workcache.rs32
2 files changed, 25 insertions, 27 deletions
diff --git a/src/libextra/test.rs b/src/libextra/test.rs
index 91db9302f64..1658bb5f161 100644
--- a/src/libextra/test.rs
+++ b/src/libextra/test.rs
@@ -31,7 +31,6 @@ use treemap::TreeMap;
 use std::clone::Clone;
 use std::comm::{stream, SharedChan, GenericPort, GenericChan};
 use std::libc;
-use std::either;
 use std::io;
 use std::result;
 use std::task;
@@ -127,8 +126,8 @@ pub type MetricDiff = TreeMap<~str,MetricChange>;
 pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) {
     let opts =
         match parse_opts(args) {
-          either::Left(o) => o,
-          either::Right(m) => fail!(m)
+            Ok(o) => o,
+            Err(msg) => fail!(msg)
         };
     if !run_tests_console(&opts, tests) { fail!("Some tests failed"); }
 }
@@ -169,7 +168,7 @@ pub struct TestOpts {
     logfile: Option<Path>
 }
 
-type OptRes = Either<TestOpts, ~str>;
+type OptRes = Result<TestOpts, ~str>;
 
 fn optgroups() -> ~[getopts::groups::OptGroup] {
     ~[groups::optflag("", "ignored", "Run ignored tests"),
@@ -228,7 +227,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
     let matches =
         match groups::getopts(args_, optgroups()) {
           Ok(m) => m,
-          Err(f) => return either::Right(getopts::fail_str(f))
+          Err(f) => return Err(getopts::fail_str(f))
         };
 
     if getopts::opt_present(&matches, "h") { usage(args[0], "h"); }
@@ -274,7 +273,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
         logfile: logfile
     };
 
-    either::Left(test_opts)
+    Ok(test_opts)
 }
 
 pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> {
@@ -1155,7 +1154,6 @@ mod tests {
                StaticTestName, DynTestName, DynTestFn};
     use test::{TestOpts, run_test};
 
-    use std::either;
     use std::comm::{stream, SharedChan};
     use tempfile;
     use std::os;
@@ -1236,8 +1234,8 @@ mod tests {
     fn first_free_arg_should_be_a_filter() {
         let args = ~[~"progname", ~"filter"];
         let opts = match parse_opts(args) {
-          either::Left(o) => o,
-          _ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
+            Ok(o) => o,
+            _ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
         };
         assert!("filter" == opts.filter.clone().unwrap());
     }
@@ -1246,8 +1244,8 @@ mod tests {
     fn parse_ignored_flag() {
         let args = ~[~"progname", ~"filter", ~"--ignored"];
         let opts = match parse_opts(args) {
-          either::Left(o) => o,
-          _ => fail!("Malformed arg in parse_ignored_flag")
+            Ok(o) => o,
+            _ => fail!("Malformed arg in parse_ignored_flag")
         };
         assert!((opts.run_ignored));
     }
diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs
index bbb8dbfcbfe..aeec4b4258b 100644
--- a/src/libextra/workcache.rs
+++ b/src/libextra/workcache.rs
@@ -19,7 +19,6 @@ use arc::{Arc,RWArc};
 use treemap::TreeMap;
 use std::cell::Cell;
 use std::comm::{PortOne, oneshot};
-use std::either::{Either, Left, Right};
 use std::{io, os, task};
 
 /**
@@ -252,9 +251,9 @@ struct Exec {
     discovered_outputs: WorkMap
 }
 
-struct Work<'self, T> {
-    prep: &'self Prep<'self>,
-    res: Option<Either<T,PortOne<(Exec,T)>>>
+enum Work<'self, T> {
+    WorkValue(T),
+    WorkFromTask(&'self Prep<'self>, PortOne<(Exec, T)>),
 }
 
 fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
@@ -426,7 +425,7 @@ impl<'self> Prep<'self> {
             db.prepare(self.fn_name, &self.declared_inputs)
         };
 
-        let res = match cached {
+        match cached {
             Some((ref disc_in, ref disc_out, ref res))
             if self.all_fresh("declared input",&self.declared_inputs) &&
                self.all_fresh("discovered input", disc_in) &&
@@ -434,7 +433,7 @@ impl<'self> Prep<'self> {
                 debug!("Cache hit!");
                 debug!("Trying to decode: %? / %? / %?",
                        disc_in, disc_out, *res);
-                Left(json_decode(*res))
+                Work::from_value(json_decode(*res))
             }
 
             _ => {
@@ -453,10 +452,9 @@ impl<'self> Prep<'self> {
                     let v = blk(&mut exe);
                     chan.send((exe, v));
                 }
-                Right(port)
+                Work::from_task(self, port)
             }
-        };
-        Work::new(self, res)
+        }
     }
 }
 
@@ -465,16 +463,18 @@ impl<'self, T:Send +
        Decodable<json::Decoder>>
     Work<'self, T> { // FIXME(#5121)
 
-    pub fn new(p: &'self Prep<'self>, e: Either<T,PortOne<(Exec,T)>>) -> Work<'self, T> {
-        Work { prep: p, res: Some(e) }
+    pub fn from_value(elt: T) -> Work<'self, T> {
+        WorkValue(elt)
+    }
+    pub fn from_task(prep: &'self Prep<'self>, port: PortOne<(Exec, T)>)
+        -> Work<'self, T> {
+        WorkFromTask(prep, port)
     }
 
     pub fn unwrap(self) -> T {
-        let Work { prep, res } = self;
-        match res {
-            None => fail!(),
-            Some(Left(v)) => v,
-            Some(Right(port)) => {
+        match self {
+            WorkValue(v) => v,
+            WorkFromTask(prep, port) => {
                 let (exe, v) = port.recv();
                 let s = json_encode(&v);
                 do prep.ctxt.db.write |db| {