Skip to content

Commit 73025bd

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 164768 b: refs/heads/try c: 5579692 h: refs/heads/master v: v3
1 parent 0e956c7 commit 73025bd

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: f8f2c7a9537c7f333b242f616aefb75a83860927
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 8443b09e361b96d1f9b7f45a65ed0d31c0e86e70
5-
refs/heads/try: 683342c3f0e6cb4142876ad06ba418df2aae1450
5+
refs/heads/try: 5579692ce77df5f8227ab7a226145f7cf18ef747
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/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)