Skip to content

Commit 5579692

Browse files
author
Jorge Aparicio
committed
libcollections: use unboxed closures in VecMap methods
1 parent 683342c commit 5579692

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/libcollections/vec_map.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use core::fmt;
2020
use core::iter;
2121
use core::iter::{Enumerate, FilterMap};
2222
use core::mem::replace;
23+
use core::ops::FnOnce;
2324

2425
use hash::{Hash, Writer};
2526
use {vec, slice};
@@ -452,8 +453,8 @@ impl<V:Clone> VecMap<V> {
452453
/// assert!(!map.update(1, vec![3i, 4], |mut old, new| { old.extend(new.into_iter()); old }));
453454
/// assert_eq!(map[1], vec![1i, 2, 3, 4]);
454455
/// ```
455-
pub fn update(&mut self, key: uint, newval: V, ff: |V, V| -> V) -> bool {
456-
self.update_with_key(key, newval, |_k, v, v1| ff(v,v1))
456+
pub fn update<F>(&mut self, key: uint, newval: V, ff: F) -> bool where F: FnOnce(V, V) -> V {
457+
self.update_with_key(key, newval, move |_k, v, v1| ff(v,v1))
457458
}
458459

459460
/// Updates a value in the map. If the key already exists in the map,
@@ -476,11 +477,9 @@ impl<V:Clone> VecMap<V> {
476477
/// assert!(!map.update_with_key(7, 20, |key, old, new| (old + new) % key));
477478
/// assert_eq!(map[7], 2);
478479
/// ```
479-
pub fn update_with_key(&mut self,
480-
key: uint,
481-
val: V,
482-
ff: |uint, V, V| -> V)
483-
-> bool {
480+
pub fn update_with_key<F>(&mut self, key: uint, val: V, ff: F) -> bool where
481+
F: FnOnce(uint, V, V) -> V
482+
{
484483
let new_val = match self.get(&key) {
485484
None => val,
486485
Some(orig) => ff(key, (*orig).clone(), val)

0 commit comments

Comments
 (0)