]> git.lizzy.rs Git - rust.git/commitdiff
Add doctests for keys() and values() of the BTreeMap collection.
authorjbranchaud <jbranchaud@gmail.com>
Fri, 5 Dec 2014 06:10:58 +0000 (00:10 -0600)
committerjbranchaud <jbranchaud@gmail.com>
Fri, 5 Dec 2014 21:40:46 +0000 (15:40 -0600)
Update keys() and values() for BTreeMap based on @Gankro's comments.

Assign keys and values to variables before doing assertion.

src/libcollections/btree/map.rs

index 8a6d26c26bf3c0651020e7d0fe3dbc447a84ee4b..b3dc9139eb32462687778072af23c630794ceeb7 100644 (file)
@@ -1068,12 +1068,38 @@ pub fn into_iter(self) -> MoveEntries<K, V> {
     }
 
     /// Gets an iterator over the keys of the map.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// use std::collections::BTreeMap;
+    ///
+    /// let mut a = BTreeMap::new();
+    /// a.insert(1u, "a");
+    /// a.insert(2u, "b");
+    ///
+    /// let keys: Vec<uint> = a.keys().cloned().collect();
+    /// assert_eq!(keys, vec![1u,2,]);
+    /// ```
     #[unstable = "matches collection reform specification, waiting for dust to settle"]
     pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
         self.iter().map(|(k, _)| k)
     }
 
     /// Gets an iterator over the values of the map.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// use std::collections::BTreeMap;
+    ///
+    /// let mut a = BTreeMap::new();
+    /// a.insert(1u, "a");
+    /// a.insert(2u, "b");
+    ///
+    /// let values: Vec<&str> = a.values().cloned().collect();
+    /// assert_eq!(values, vec!["a","b"]);
+    /// ```
     #[unstable = "matches collection reform specification, waiting for dust to settle"]
     pub fn values<'a>(&'a self) -> Values<'a, K, V> {
         self.iter().map(|(_, v)| v)