Skip to content

Commit 1eccb54

Browse files
committed
auto merge of #19685 : jbranchaud/rust/add-btreemap-iter-doctests, r=Gankro
2 parents de64f85 + d946426 commit 1eccb54

File tree

1 file changed

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

1 file changed

+33
-0
lines changed

src/libcollections/btree/map.rs

+33
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,24 @@ impl<K, V> BTreeMap<K, V> {
11311131
}
11321132

11331133
/// Gets a mutable iterator over the entries of the map.
1134+
///
1135+
/// # Examples
1136+
///
1137+
/// ```
1138+
/// use std::collections::BTreeMap;
1139+
///
1140+
/// let mut map = BTreeMap::new();
1141+
/// map.insert("a", 1u);
1142+
/// map.insert("b", 2u);
1143+
/// map.insert("c", 3u);
1144+
///
1145+
/// // add 10 to the value if the key isn't "a"
1146+
/// for (key, value) in map.iter_mut() {
1147+
/// if key != &"a" {
1148+
/// *value += 10;
1149+
/// }
1150+
/// }
1151+
/// ```
11341152
#[unstable = "matches collection reform specification, waiting for dust to settle"]
11351153
pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, K, V> {
11361154
let len = self.len();
@@ -1145,6 +1163,21 @@ impl<K, V> BTreeMap<K, V> {
11451163
}
11461164

11471165
/// Gets an owning iterator over the entries of the map.
1166+
///
1167+
/// # Examples
1168+
///
1169+
/// ```
1170+
/// use std::collections::BTreeMap;
1171+
///
1172+
/// let mut map = BTreeMap::new();
1173+
/// map.insert(1u, "a");
1174+
/// map.insert(2u, "b");
1175+
/// map.insert(3u, "c");
1176+
///
1177+
/// for (key, value) in map.into_iter() {
1178+
/// println!("{}: {}", key, value);
1179+
/// }
1180+
/// ```
11481181
#[unstable = "matches collection reform specification, waiting for dust to settle"]
11491182
pub fn into_iter(self) -> MoveEntries<K, V> {
11501183
let len = self.len();

0 commit comments

Comments
 (0)