]> git.lizzy.rs Git - rust.git/commitdiff
Add doctests for `iter_mut` and `into_iter` of BTreeMap.
authorjbranchaud <jbranchaud@gmail.com>
Wed, 10 Dec 2014 04:08:44 +0000 (22:08 -0600)
committerjbranchaud <jbranchaud@gmail.com>
Wed, 10 Dec 2014 04:19:23 +0000 (22:19 -0600)
Add spacing as dictated by standard rust code style.

src/libcollections/btree/map.rs

index 86eaa04b3e2e381835761058b7ace660a5281bf1..51d64e2dba5ce6719f1cccc0fdf5855ffee0b791 100644 (file)
@@ -1058,6 +1058,24 @@ pub fn iter<'a>(&'a self) -> Entries<'a, 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();
@@ -1072,6 +1090,21 @@ pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, 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();