Skip to content

Commit d946426

Browse files
committed
Add doctests for iter_mut and into_iter of BTreeMap.
Add spacing as dictated by standard rust code style.
1 parent 4c692d3 commit d946426

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
@@ -1058,6 +1058,24 @@ impl<K, V> BTreeMap<K, V> {
10581058
}
10591059

10601060
/// Gets a mutable iterator over the entries of the map.
1061+
///
1062+
/// # Examples
1063+
///
1064+
/// ```
1065+
/// use std::collections::BTreeMap;
1066+
///
1067+
/// let mut map = BTreeMap::new();
1068+
/// map.insert("a", 1u);
1069+
/// map.insert("b", 2u);
1070+
/// map.insert("c", 3u);
1071+
///
1072+
/// // add 10 to the value if the key isn't "a"
1073+
/// for (key, value) in map.iter_mut() {
1074+
/// if key != &"a" {
1075+
/// *value += 10;
1076+
/// }
1077+
/// }
1078+
/// ```
10611079
#[unstable = "matches collection reform specification, waiting for dust to settle"]
10621080
pub fn iter_mut<'a>(&'a mut self) -> MutEntries<'a, K, V> {
10631081
let len = self.len();
@@ -1072,6 +1090,21 @@ impl<K, V> BTreeMap<K, V> {
10721090
}
10731091

10741092
/// Gets an owning iterator over the entries of the map.
1093+
///
1094+
/// # Examples
1095+
///
1096+
/// ```
1097+
/// use std::collections::BTreeMap;
1098+
///
1099+
/// let mut map = BTreeMap::new();
1100+
/// map.insert(1u, "a");
1101+
/// map.insert(2u, "b");
1102+
/// map.insert(3u, "c");
1103+
///
1104+
/// for (key, value) in map.into_iter() {
1105+
/// println!("{}: {}", key, value);
1106+
/// }
1107+
/// ```
10751108
#[unstable = "matches collection reform specification, waiting for dust to settle"]
10761109
pub fn into_iter(self) -> MoveEntries<K, V> {
10771110
let len = self.len();

0 commit comments

Comments
 (0)