Skip to content

Commit 3e220b0

Browse files
committed
---
yaml --- r: 94786 b: refs/heads/try c: 2ca0b58 h: refs/heads/master v: v3
1 parent 37dcb5b commit 3e220b0

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
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: 0da105a8b7b6b1e0568e8ff20f6ff4b13cc7ecc2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d3e57dca68fde4effdda3e4ae2887aa535fcd6
5-
refs/heads/try: 2277d78d33f1a110ba107064b4da5c2f5b7d941f
5+
refs/heads/try: 2ca0b58f60e55afdffc68a8aef24704ad2a2a2e3
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/hashmap.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,43 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
354354

355355
/// Modify and return the value corresponding to the key in the map, or
356356
/// insert and return a new value if it doesn't exist.
357+
///
358+
/// This method allows for all insertion behaviours of a hashmap,
359+
/// see methods like `insert`, `find_or_insert` and
360+
/// `insert_or_update_with` for less general and more friendly
361+
/// variations of this.
362+
///
363+
/// # Example
364+
///
365+
/// ```rust
366+
/// use std::hashmap::HashMap;
367+
///
368+
/// // map some strings to vectors of strings
369+
/// let mut map = HashMap::<~str, ~[~str]>::new();
370+
/// map.insert(~"a key", ~[~"value"]);
371+
/// map.insert(~"z key", ~[~"value"]);
372+
///
373+
/// let new = ~[~"a key", ~"b key", ~"z key"];
374+
/// for k in new.move_iter() {
375+
/// map.mangle(k, ~"new value",
376+
/// // if the key doesn't exist in the map yet, add it in
377+
/// // the obvious way.
378+
/// |_k, v| ~[v],
379+
/// // if the key does exist either prepend or append this
380+
/// // new value based on the first letter of the key.
381+
/// |key, already, new| {
382+
/// if key.starts_with("z") {
383+
/// already.unshift(new);
384+
/// } else {
385+
/// already.push(new);
386+
/// }
387+
/// });
388+
/// }
389+
///
390+
/// for (k, v) in map.iter() {
391+
/// println!("{} -> {:?}", *k, *v);
392+
/// }
393+
/// ```
357394
pub fn mangle<'a,
358395
A>(
359396
&'a mut self,

0 commit comments

Comments
 (0)