about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-12-13 11:02:17 +0000
committerbors <bors@rust-lang.org>2014-12-13 11:02:17 +0000
commit1eccb54bd61c666a38874e6ddaa1f16fa6e3d0fd (patch)
tree81e61fdb2dd131dacdc8f7fc8686807be36e3d22
parentde64f85c6ec8296e68d859a07ea179d3e69eeeb4 (diff)
parentd946426699c8316d587cc382c8a2e7030b53aed5 (diff)
downloadrust-1eccb54bd61c666a38874e6ddaa1f16fa6e3d0fd.tar.gz
rust-1eccb54bd61c666a38874e6ddaa1f16fa6e3d0fd.zip
auto merge of #19685 : jbranchaud/rust/add-btreemap-iter-doctests, r=Gankro
-rw-r--r--src/libcollections/btree/map.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs
index f0a4902bb92..3d5067d5a51 100644
--- a/src/libcollections/btree/map.rs
+++ b/src/libcollections/btree/map.rs
@@ -1131,6 +1131,24 @@ impl<K, V> BTreeMap<K, V> {
     }
 
     /// Gets a mutable iterator over the entries of the map.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::collections::BTreeMap;
+    ///
+    /// let mut map = BTreeMap::new();
+    /// map.insert("a", 1u);
+    /// map.insert("b", 2u);
+    /// map.insert("c", 3u);
+    ///
+    /// // add 10 to the value if the key isn't "a"
+    /// for (key, value) in map.iter_mut() {
+    ///     if key != &"a" {
+    ///         *value += 10;
+    ///     }
+    /// }
+    /// ```
     #[unstable = "matches collection reform specification, waiting for dust to settle"]
     pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, K, V> {
         let len = self.len();
@@ -1145,6 +1163,21 @@ impl<K, V> BTreeMap<K, V> {
     }
 
     /// Gets an owning iterator over the entries of the map.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::collections::BTreeMap;
+    ///
+    /// let mut map = BTreeMap::new();
+    /// map.insert(1u, "a");
+    /// map.insert(2u, "b");
+    /// map.insert(3u, "c");
+    ///
+    /// for (key, value) in map.into_iter() {
+    ///     println!("{}: {}", key, value);
+    /// }
+    /// ```
     #[unstable = "matches collection reform specification, waiting for dust to settle"]
     pub fn into_iter(self) -> MoveEntries<K, V> {
         let len = self.len();