Skip to content

Commit fa99ebc

Browse files
authored
Rollup merge of #122817 - ultrabear:ultrabear_btreedoc, r=Nilstrieb
Doc Guarantee: BTree(Set|Map): `IntoIter` Iterate in Sorted by key Order This Doc-only PR adds text to the IntoIterator implementation and IntoIter type for both BTreeMap and BTreeSet that states that the returned items will be in sorted-by-key order, this is a guarantee that is made by the iter() and iter_mut() methods of BTreeMap/Set and BTreeMap respectively, but not on into_iter methods or types. I don't know how the IntoIter iteration would not be sorted by key, and I would like to rely on that behavior for my prefix_array crate. The text appended to IntoIter documentation is based on each types respective iter() method documentation, as is the text used in the IntoIterator documentation; they are slightly inconsistent between Set/Map, but they are consistent within their own types documentation.
2 parents f0feebb + beb0c22 commit fa99ebc

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

library/alloc/src/collections/btree/map.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
7272
/// `BTreeMap` that observed the logic error and not result in undefined behavior. This could
7373
/// include panics, incorrect results, aborts, memory leaks, and non-termination.
7474
///
75-
/// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::values`], or
75+
/// Iterators obtained from functions such as [`BTreeMap::iter`], [`BTreeMap::into_iter`], [`BTreeMap::values`], or
7676
/// [`BTreeMap::keys`] produce their items in order by key, and take worst-case logarithmic and
7777
/// amortized constant time per item returned.
7878
///
@@ -415,7 +415,7 @@ impl<'a, K: 'a, V: 'a> Default for IterMut<'a, K, V> {
415415
}
416416
}
417417

418-
/// An owning iterator over the entries of a `BTreeMap`.
418+
/// An owning iterator over the entries of a `BTreeMap`, sorted by key.
419419
///
420420
/// This `struct` is created by the [`into_iter`] method on [`BTreeMap`]
421421
/// (provided by the [`IntoIterator`] trait). See its documentation for more.
@@ -1637,6 +1637,7 @@ impl<K, V, A: Allocator + Clone> IntoIterator for BTreeMap<K, V, A> {
16371637
type Item = (K, V);
16381638
type IntoIter = IntoIter<K, V, A>;
16391639

1640+
/// Gets an owning iterator over the entries of the map, sorted by key.
16401641
fn into_iter(self) -> IntoIter<K, V, A> {
16411642
let mut me = ManuallyDrop::new(self);
16421643
if let Some(root) = me.root.take() {

library/alloc/src/collections/btree/set.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::alloc::{Allocator, Global};
2727
/// `BTreeSet` that observed the logic error and not result in undefined behavior. This could
2828
/// include panics, incorrect results, aborts, memory leaks, and non-termination.
2929
///
30-
/// Iterators returned by [`BTreeSet::iter`] produce their items in order, and take worst-case
30+
/// Iterators returned by [`BTreeSet::iter`] and [`BTreeSet::into_iter`] produce their items in order, and take worst-case
3131
/// logarithmic and amortized constant time per item returned.
3232
///
3333
/// [`Cell`]: core::cell::Cell
@@ -140,7 +140,7 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
140140
}
141141
}
142142

143-
/// An owning iterator over the items of a `BTreeSet`.
143+
/// An owning iterator over the items of a `BTreeSet` in ascending order.
144144
///
145145
/// This `struct` is created by the [`into_iter`] method on [`BTreeSet`]
146146
/// (provided by the [`IntoIterator`] trait). See its documentation for more.
@@ -1237,7 +1237,7 @@ impl<T, A: Allocator + Clone> IntoIterator for BTreeSet<T, A> {
12371237
type Item = T;
12381238
type IntoIter = IntoIter<T, A>;
12391239

1240-
/// Gets an iterator for moving out the `BTreeSet`'s contents.
1240+
/// Gets an iterator for moving out the `BTreeSet`'s contents in ascending order.
12411241
///
12421242
/// # Examples
12431243
///

0 commit comments

Comments
 (0)