Skip to content

Commit ae60f9c

Browse files
committed
rollup merge of rust-lang#19592: jbranchaud/add-btreemap-iter-doctest
I'm interested in including doctests for `BTreeMap`'s `iter_mut` and `into_iter` methods in this PR as well, but I am not sure of the best way to demonstrate/test what they do for the doctests.
2 parents 63ef9e9 + 9cb26e2 commit ae60f9c

File tree

1 file changed

+18
-0
lines changed
  • src/libcollections/btree

1 file changed

+18
-0
lines changed

src/libcollections/btree/map.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,24 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
10261026

10271027
impl<K, V> BTreeMap<K, V> {
10281028
/// Gets an iterator over the entries of the map.
1029+
///
1030+
/// # Example
1031+
///
1032+
/// ```
1033+
/// use std::collections::BTreeMap;
1034+
///
1035+
/// let mut map = BTreeMap::new();
1036+
/// map.insert(1u, "a");
1037+
/// map.insert(2u, "b");
1038+
/// map.insert(3u, "c");
1039+
///
1040+
/// for (key, value) in map.iter() {
1041+
/// println!("{}: {}", key, value);
1042+
/// }
1043+
///
1044+
/// let (first_key, first_value) = map.iter().next().unwrap();
1045+
/// assert_eq!((*first_key, *first_value), (1u, "a"));
1046+
/// ```
10291047
#[unstable = "matches collection reform specification, waiting for dust to settle"]
10301048
pub fn iter<'a>(&'a self) -> Entries<'a, K, V> {
10311049
let len = self.len();

0 commit comments

Comments
 (0)