diff options
| author | jbranchaud <jbranchaud@gmail.com> | 2014-12-05 00:10:58 -0600 |
|---|---|---|
| committer | jbranchaud <jbranchaud@gmail.com> | 2014-12-05 15:40:46 -0600 |
| commit | d6b6df0dfa4fb3488e01abf3df0eeb4c5c3560f8 (patch) | |
| tree | 1a7e2a56eefb9d823abf91aca209c6661a57103a | |
| parent | 361baabb07b2fb921d0f556d0787b3ea7ef86746 (diff) | |
| download | rust-d6b6df0dfa4fb3488e01abf3df0eeb4c5c3560f8.tar.gz rust-d6b6df0dfa4fb3488e01abf3df0eeb4c5c3560f8.zip | |
Add doctests for keys() and values() of the BTreeMap collection.
Update keys() and values() for BTreeMap based on @Gankro's comments. Assign keys and values to variables before doing assertion.
| -rw-r--r-- | src/libcollections/btree/map.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 8a6d26c26bf..b3dc9139eb3 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -1068,12 +1068,38 @@ impl<K, V> BTreeMap<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) |
