diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-06-04 16:24:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-04 16:24:09 +0200 |
| commit | 98421b765fa977e397116d0c87099c2b762ff1e4 (patch) | |
| tree | 73fce133dbe0c799d479638dfcf95e15b48290ee | |
| parent | 005490cbbcaab93c793f7b9a9001973b99c703ae (diff) | |
| parent | a20cf473e7b888f9ef7995971f0c5613a81e68ff (diff) | |
| download | rust-98421b765fa977e397116d0c87099c2b762ff1e4.tar.gz rust-98421b765fa977e397116d0c87099c2b762ff1e4.zip | |
Rollup merge of #141924 - rs-sac:extr-doc, r=jhpratt
Lightly tweak docs for BTree{Map,Set}::extract_if
- Move explanations into comments to match style
- Explain the second examples
- Make variable names match the data structure
Related rust-lang/rust#70530
| -rw-r--r-- | library/alloc/src/collections/btree/map.rs | 4 | ||||
| -rw-r--r-- | library/alloc/src/collections/btree/set.rs | 10 |
2 files changed, 7 insertions, 7 deletions
diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 52b98291ff9..17c16e4aaff 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -1416,18 +1416,18 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> { /// /// # Examples /// - /// Splitting a map into even and odd keys, reusing the original map: - /// /// ``` /// #![feature(btree_extract_if)] /// use std::collections::BTreeMap; /// + /// // Splitting a map into even and odd keys, reusing the original map: /// let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x)).collect(); /// let evens: BTreeMap<_, _> = map.extract_if(.., |k, _v| k % 2 == 0).collect(); /// let odds = map; /// assert_eq!(evens.keys().copied().collect::<Vec<_>>(), [0, 2, 4, 6]); /// assert_eq!(odds.keys().copied().collect::<Vec<_>>(), [1, 3, 5, 7]); /// + /// // Splitting a map into low and high halves, reusing the original map: /// let mut map: BTreeMap<i32, i32> = (0..8).map(|x| (x, x)).collect(); /// let low: BTreeMap<_, _> = map.extract_if(0..4, |_k, _v| true).collect(); /// let high = map; diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index 780bd8b0dd1..51418036f42 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -1201,21 +1201,21 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> { /// [`retain`]: BTreeSet::retain /// # Examples /// - /// Splitting a set into even and odd values, reusing the original set: - /// /// ``` /// #![feature(btree_extract_if)] /// use std::collections::BTreeSet; /// + /// // Splitting a set into even and odd values, reusing the original set: /// let mut set: BTreeSet<i32> = (0..8).collect(); /// let evens: BTreeSet<_> = set.extract_if(.., |v| v % 2 == 0).collect(); /// let odds = set; /// assert_eq!(evens.into_iter().collect::<Vec<_>>(), vec![0, 2, 4, 6]); /// assert_eq!(odds.into_iter().collect::<Vec<_>>(), vec![1, 3, 5, 7]); /// - /// let mut map: BTreeSet<i32> = (0..8).collect(); - /// let low: BTreeSet<_> = map.extract_if(0..4, |_v| true).collect(); - /// let high = map; + /// // Splitting a set into low and high halves, reusing the original set: + /// let mut set: BTreeSet<i32> = (0..8).collect(); + /// let low: BTreeSet<_> = set.extract_if(0..4, |_v| true).collect(); + /// let high = set; /// assert_eq!(low.into_iter().collect::<Vec<_>>(), [0, 1, 2, 3]); /// assert_eq!(high.into_iter().collect::<Vec<_>>(), [4, 5, 6, 7]); /// ``` |
