Skip to content

Commit 9cb26e2

Browse files
committed
Add a doctest for BTreeMap's iter method.
1 parent 6f4c11b commit 9cb26e2

File tree

1 file changed

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

1 file changed

+18
-0
lines changed

src/libcollections/btree/map.rs

+18
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)