From f91d87e6a03f4e64034ee8fa073ac8d47e71dc88 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 2 Dec 2014 14:07:40 -0500 Subject: libcollections: fix fallout --- src/libcollections/vec_map.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/libcollections/vec_map.rs') diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 3b8c690e047..9356c769d26 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -141,14 +141,18 @@ impl VecMap { /// The iterator's element type is `uint`. #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn keys<'r>(&'r self) -> Keys<'r, V> { - self.iter().map(|(k, _v)| k) + fn first((a, _): (A, B)) -> A { a } + + self.iter().map(first) } /// Returns an iterator visiting all values in ascending order by the keys. /// The iterator's element type is `&'r V`. #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn values<'r>(&'r self) -> Values<'r, V> { - self.iter().map(|(_k, v)| v) + fn second((_, b): (A, B)) -> B { b } + + self.iter().map(second) } /// Returns an iterator visiting all key-value pairs in ascending order by the keys. @@ -620,12 +624,11 @@ iterator!(impl MutEntries -> (uint, &'a mut V), as_mut) double_ended_iterator!(impl MutEntries -> (uint, &'a mut V), as_mut) /// Forward iterator over the keys of a map -pub type Keys<'a, V> = - iter::Map<'static, (uint, &'a V), uint, Entries<'a, V>>; +pub type Keys<'a, V> = iter::Map<(uint, &'a V), uint, Entries<'a, V>, fn((uint, &'a V)) -> uint>; /// Forward iterator over the values of a map pub type Values<'a, V> = - iter::Map<'static, (uint, &'a V), &'a V, Entries<'a, V>>; + iter::Map<(uint, &'a V), &'a V, Entries<'a, V>, fn((uint, &'a V)) -> &'a V>; /// Iterator over the key-value pairs of a map, the iterator consumes the map pub type MoveItems = -- cgit 1.4.1-3-g733a5 From 4f6f6af281b47a95576b648ac924d79835f16db2 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 2 Dec 2014 21:05:30 -0500 Subject: libcollections: fix fallout --- src/libcollections/vec_map.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/libcollections/vec_map.rs') diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 9356c769d26..ce5817e8d9e 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -234,10 +234,12 @@ impl VecMap { /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] pub fn into_iter(&mut self) -> MoveItems { - let values = replace(&mut self.v, vec!()); - values.into_iter().enumerate().filter_map(|(i, v)| { + fn filter((i, v): (uint, Option)) -> Option<(uint, A)> { v.map(|v| (i, v)) - }) + } + + let values = replace(&mut self.v, vec!()); + values.into_iter().enumerate().filter_map(filter) } /// Return the number of elements in the map. @@ -631,8 +633,11 @@ pub type Values<'a, V> = iter::Map<(uint, &'a V), &'a V, Entries<'a, V>, fn((uint, &'a V)) -> &'a V>; /// Iterator over the key-value pairs of a map, the iterator consumes the map -pub type MoveItems = - FilterMap<'static, (uint, Option), (uint, V), Enumerate>>>; +pub type MoveItems = FilterMap< + (uint, Option), + (uint, V), + Enumerate>>, + fn((uint, Option)) -> Option<(uint, V)>>; #[cfg(test)] mod test_map { -- cgit 1.4.1-3-g733a5 From 5579692ce77df5f8227ab7a226145f7cf18ef747 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 5 Dec 2014 17:03:04 -0500 Subject: libcollections: use unboxed closures in `VecMap` methods --- src/libcollections/vec_map.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/libcollections/vec_map.rs') diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index ce5817e8d9e..cc2fd0a6646 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -20,6 +20,7 @@ use core::fmt; use core::iter; use core::iter::{Enumerate, FilterMap}; use core::mem::replace; +use core::ops::FnOnce; use hash::{Hash, Writer}; use {vec, slice}; @@ -452,8 +453,8 @@ impl VecMap { /// assert!(!map.update(1, vec![3i, 4], |mut old, new| { old.extend(new.into_iter()); old })); /// assert_eq!(map[1], vec![1i, 2, 3, 4]); /// ``` - pub fn update(&mut self, key: uint, newval: V, ff: |V, V| -> V) -> bool { - self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)) + pub fn update(&mut self, key: uint, newval: V, ff: F) -> bool where F: FnOnce(V, V) -> V { + self.update_with_key(key, newval, move |_k, v, v1| ff(v,v1)) } /// Updates a value in the map. If the key already exists in the map, @@ -476,11 +477,9 @@ impl VecMap { /// assert!(!map.update_with_key(7, 20, |key, old, new| (old + new) % key)); /// assert_eq!(map[7], 2); /// ``` - pub fn update_with_key(&mut self, - key: uint, - val: V, - ff: |uint, V, V| -> V) - -> bool { + pub fn update_with_key(&mut self, key: uint, val: V, ff: F) -> bool where + F: FnOnce(uint, V, V) -> V + { let new_val = match self.get(&key) { None => val, Some(orig) => ff(key, (*orig).clone(), val) -- cgit 1.4.1-3-g733a5