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.
This commit is contained in:
parent
361baabb07
commit
d6b6df0dfa
1 changed files with 26 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue