about summary refs log tree commit diff
path: root/src/libextra
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-08-07 13:23:07 -0700
committerbors <bors@rust-lang.org>2013-08-07 13:23:07 -0700
commit98ec79c9576052d9fededd3b72b47d387c1c455d (patch)
tree1bb89d47e3668a024cc4bc9d252991ef78d1e4d5 /src/libextra
parentcdba212e7299f6bda752abbb9f887c51d96f7586 (diff)
parent19e17f54a02e484f1ab4fd809caa0aaf3f3d14bc (diff)
downloadrust-98ec79c9576052d9fededd3b72b47d387c1c455d.tar.gz
rust-98ec79c9576052d9fededd3b72b47d387c1c455d.zip
auto merge of #8294 : erickt/rust/map-move, r=bblum
According to #7887, we've decided to use the syntax of `fn map<U>(f: &fn(&T) -> U) -> U`, which passes a reference to the closure, and to `fn map_move<U>(f: &fn(T) -> U) -> U` which moves the value into the closure. This PR adds these `.map_move()` functions to `Option` and `Result`.

In addition, it has these other minor features:
 
* Replaces a couple uses of `option.get()`, `result.get()`, and `result.get_err()` with `option.unwrap()`, `result.unwrap()`, and `result.unwrap_err()`. (See #8268 and #8288 for a more thorough adaptation of this functionality.
* Removes `option.take_map()` and `option.take_map_default()`. These two functions can be easily written as `.take().map_move(...)`.
* Adds a better error message to `result.unwrap()` and `result.unwrap_err()`.
Diffstat (limited to 'src/libextra')
-rw-r--r--src/libextra/dlist.rs20
-rw-r--r--src/libextra/num/bigint.rs6
-rw-r--r--src/libextra/smallintmap.rs2
-rw-r--r--src/libextra/term.rs4
-rw-r--r--src/libextra/test.rs8
-rw-r--r--src/libextra/treemap.rs2
-rw-r--r--src/libextra/workcache.rs4
7 files changed, 23 insertions, 23 deletions
diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs
index 75487a44f26..b0839a55795 100644
--- a/src/libextra/dlist.rs
+++ b/src/libextra/dlist.rs
@@ -164,7 +164,7 @@ impl<T> DList<T> {
     /// Remove the first Node and return it, or None if the list is empty
     #[inline]
     fn pop_front_node(&mut self) -> Option<~Node<T>> {
-        do self.list_head.take().map_consume |mut front_node| {
+        do self.list_head.take().map_move |mut front_node| {
             self.length -= 1;
             match front_node.next.take() {
                 Some(node) => self.list_head = link_with_prev(node, Rawlink::none()),
@@ -190,7 +190,7 @@ impl<T> DList<T> {
     /// Remove the last Node and return it, or None if the list is empty
     #[inline]
     fn pop_back_node(&mut self) -> Option<~Node<T>> {
-        do self.list_tail.resolve().map_consume_default(None) |tail| {
+        do self.list_tail.resolve().map_move_default(None) |tail| {
             self.length -= 1;
             self.list_tail = tail.prev;
             match tail.prev.resolve() {
@@ -237,7 +237,7 @@ impl<T> Deque<T> for DList<T> {
     ///
     /// O(1)
     fn pop_front(&mut self) -> Option<T> {
-        self.pop_front_node().map_consume(|~Node{value, _}| value)
+        self.pop_front_node().map_move(|~Node{value, _}| value)
     }
 
     /// Add an element last in the list
@@ -251,7 +251,7 @@ impl<T> Deque<T> for DList<T> {
     ///
     /// O(1)
     fn pop_back(&mut self) -> Option<T> {
-        self.pop_back_node().map_consume(|~Node{value, _}| value)
+        self.pop_back_node().map_move(|~Node{value, _}| value)
     }
 }
 
@@ -267,7 +267,7 @@ impl<T> DList<T> {
     /// If the list is empty, do nothing.
     #[inline]
     pub fn rotate_forward(&mut self) {
-        do self.pop_back_node().map_consume |tail| {
+        do self.pop_back_node().map_move |tail| {
             self.push_front_node(tail)
         };
     }
@@ -277,7 +277,7 @@ impl<T> DList<T> {
     /// If the list is empty, do nothing.
     #[inline]
     pub fn rotate_backward(&mut self) {
-        do self.pop_front_node().map_consume |head| {
+        do self.pop_front_node().map_move |head| {
             self.push_back_node(head)
         };
     }
@@ -463,7 +463,7 @@ impl<'self, A> DoubleEndedIterator<&'self A> for DListIterator<'self, A> {
         if self.nelem == 0 {
             return None;
         }
-        do self.tail.resolve().map_consume |prev| {
+        do self.tail.resolve().map_move |prev| {
             self.nelem -= 1;
             self.tail = prev.prev;
             &prev.value
@@ -477,7 +477,7 @@ impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> {
         if self.nelem == 0 {
             return None;
         }
-        do self.head.resolve().map_consume |next| {
+        do self.head.resolve().map_move |next| {
             self.nelem -= 1;
             self.head = match next.next {
                 Some(ref mut node) => Rawlink::some(&mut **node),
@@ -499,7 +499,7 @@ impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, A>
         if self.nelem == 0 {
             return None;
         }
-        do self.tail.resolve().map_consume |prev| {
+        do self.tail.resolve().map_move |prev| {
             self.nelem -= 1;
             self.tail = prev.prev;
             &mut prev.value
@@ -553,7 +553,7 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
         if self.nelem == 0 {
             return None
         }
-        self.head.resolve().map_consume(|head| &mut head.value)
+        self.head.resolve().map_move(|head| &mut head.value)
     }
 }
 
diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs
index bced00902c9..c3737d44e38 100644
--- a/src/libextra/num/bigint.rs
+++ b/src/libextra/num/bigint.rs
@@ -548,7 +548,7 @@ impl BigUint {
 
     pub fn new(v: ~[BigDigit]) -> BigUint {
         // omit trailing zeros
-        let new_len = v.rposition(|n| *n != 0).map_default(0, |p| *p + 1);
+        let new_len = v.rposition(|n| *n != 0).map_move_default(0, |p| p + 1);
 
         if new_len == v.len() { return BigUint { data: v }; }
         let mut v = v;
@@ -1145,7 +1145,7 @@ impl BigInt {
             start = 1;
         }
         return BigUint::parse_bytes(buf.slice(start, buf.len()), radix)
-            .map_consume(|bu| BigInt::from_biguint(sign, bu));
+            .map_move(|bu| BigInt::from_biguint(sign, bu));
     }
 
     pub fn to_uint(&self) -> uint {
@@ -2028,7 +2028,7 @@ mod bigint_tests {
     #[test]
     fn test_from_str_radix() {
         fn check(s: &str, ans: Option<int>) {
-            let ans = ans.map(|&n| IntConvertible::from_int::<BigInt>(n));
+            let ans = ans.map_move(|n| IntConvertible::from_int::<BigInt>(n));
             assert_eq!(FromStrRadix::from_str_radix(s, 10), ans);
         }
         check("10", Some(10));
diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs
index 3f62317eb89..e5116f19afa 100644
--- a/src/libextra/smallintmap.rs
+++ b/src/libextra/smallintmap.rs
@@ -203,7 +203,7 @@ impl<V> SmallIntMap<V> {
     {
         let values = replace(&mut self.v, ~[]);
         values.consume_iter().enumerate().filter_map(|(i, v)| {
-            v.map_consume(|v| (i, v))
+            v.map_move(|v| (i, v))
         })
     }
 }
diff --git a/src/libextra/term.rs b/src/libextra/term.rs
index 1cfb4f4afa6..2173eb838e5 100644
--- a/src/libextra/term.rs
+++ b/src/libextra/term.rs
@@ -127,7 +127,7 @@ impl Terminal {
         let inf = ti.unwrap();
         let nc = if inf.strings.find_equiv(&("setaf")).is_some()
                  && inf.strings.find_equiv(&("setab")).is_some() {
-                     inf.numbers.find_equiv(&("colors")).map_consume_default(0, |&n| n)
+                     inf.numbers.find_equiv(&("colors")).map_move_default(0, |&n| n)
                  } else { 0 };
 
         return Ok(Terminal {out: out, ti: inf, num_colors: nc});
@@ -220,7 +220,7 @@ impl Terminal {
                 cap = self.ti.strings.find_equiv(&("op"));
             }
         }
-        let s = do cap.map_consume_default(Err(~"can't find terminfo capability `sgr0`")) |op| {
+        let s = do cap.map_move_default(Err(~"can't find terminfo capability `sgr0`")) |op| {
             expand(*op, [], &mut Variables::new())
         };
         if s.is_ok() {
diff --git a/src/libextra/test.rs b/src/libextra/test.rs
index e87be146226..761cb1bd76f 100644
--- a/src/libextra/test.rs
+++ b/src/libextra/test.rs
@@ -238,20 +238,20 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
     let run_ignored = getopts::opt_present(&matches, "ignored");
 
     let logfile = getopts::opt_maybe_str(&matches, "logfile");
-    let logfile = logfile.map(|s| Path(*s));
+    let logfile = logfile.map_move(|s| Path(s));
 
     let run_benchmarks = getopts::opt_present(&matches, "bench");
     let run_tests = ! run_benchmarks ||
         getopts::opt_present(&matches, "test");
 
     let ratchet_metrics = getopts::opt_maybe_str(&matches, "ratchet-metrics");
-    let ratchet_metrics = ratchet_metrics.map(|s| Path(*s));
+    let ratchet_metrics = ratchet_metrics.map_move(|s| Path(s));
 
     let ratchet_noise_percent = getopts::opt_maybe_str(&matches, "ratchet-noise-percent");
-    let ratchet_noise_percent = ratchet_noise_percent.map(|s| f64::from_str(*s).unwrap());
+    let ratchet_noise_percent = ratchet_noise_percent.map_move(|s| f64::from_str(s).unwrap());
 
     let save_metrics = getopts::opt_maybe_str(&matches, "save-metrics");
-    let save_metrics = save_metrics.map(|s| Path(*s));
+    let save_metrics = save_metrics.map_move(|s| Path(s));
 
     let test_opts = TestOpts {
         filter: filter,
diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs
index 487ad050e78..ab7d47255da 100644
--- a/src/libextra/treemap.rs
+++ b/src/libextra/treemap.rs
@@ -394,7 +394,7 @@ impl<'self, T> Iterator<&'self T> for TreeSetIterator<'self, T> {
     /// Advance the iterator to the next node (in order). If there are no more nodes, return `None`.
     #[inline]
     fn next(&mut self) -> Option<&'self T> {
-        do self.iter.next().map |&(value, _)| { value }
+        do self.iter.next().map_move |(value, _)| { value }
     }
 }
 
diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs
index 0256519abb7..b4ba8acae47 100644
--- a/src/libextra/workcache.rs
+++ b/src/libextra/workcache.rs
@@ -221,7 +221,7 @@ fn digest<T:Encodable<json::Encoder>>(t: &T) -> ~str {
 fn digest_file(path: &Path) -> ~str {
     let mut sha = ~Sha1::new();
     let s = io::read_whole_file_str(path);
-    (*sha).input_str(*s.get_ref());
+    (*sha).input_str(s.unwrap());
     (*sha).result_str()
 }
 
@@ -378,7 +378,7 @@ fn test() {
     let pth = Path("foo.c");
     {
         let r = io::file_writer(&pth, [io::Create]);
-        r.get_ref().write_str("int main() { return 0; }");
+        r.unwrap().write_str("int main() { return 0; }");
     }
 
     let cx = Context::new(RWArc::new(Database::new(Path("db.json"))),