@@ -20,6 +20,7 @@ use core::fmt;
20
20
use core:: iter;
21
21
use core:: iter:: { Enumerate , FilterMap } ;
22
22
use core:: mem:: replace;
23
+ use core:: ops:: FnOnce ;
23
24
24
25
use hash:: { Hash , Writer } ;
25
26
use { vec, slice} ;
@@ -452,8 +453,8 @@ impl<V:Clone> VecMap<V> {
452
453
/// assert!(!map.update(1, vec![3i, 4], |mut old, new| { old.extend(new.into_iter()); old }));
453
454
/// assert_eq!(map[1], vec![1i, 2, 3, 4]);
454
455
/// ```
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) )
457
458
}
458
459
459
460
/// Updates a value in the map. If the key already exists in the map,
@@ -476,11 +477,9 @@ impl<V:Clone> VecMap<V> {
476
477
/// assert!(!map.update_with_key(7, 20, |key, old, new| (old + new) % key));
477
478
/// assert_eq!(map[7], 2);
478
479
/// ```
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
+ {
484
483
let new_val = match self . get ( & key) {
485
484
None => val,
486
485
Some ( orig) => ff ( key, ( * orig) . clone ( ) , val)
0 commit comments