From b4ed584f6cefe7ec2f111a1325dbb7f797650e63 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 6 Dec 2016 15:47:33 -1000 Subject: [PATCH] Indicate that `BTreeSet::iter` returns values in ascending order. Fixes /~https://github.com/rust-lang/rust/issues/38204. --- src/libcollections/btree/set.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index ffd5d7a919271..34674e3a0bd30 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -173,7 +173,7 @@ impl BTreeSet { } impl BTreeSet { - /// Gets an iterator over the `BTreeSet`'s contents. + /// Gets an iterator that visits the values in the `BTreeSet` in ascending order. /// /// # Examples /// @@ -187,6 +187,19 @@ impl BTreeSet { /// assert_eq!(set_iter.next(), Some(&3)); /// assert_eq!(set_iter.next(), None); /// ``` + /// + /// Values returned by the iterator are returned in ascending order: + /// + /// ``` + /// use std::collections::BTreeSet; + /// + /// let set: BTreeSet = [3, 1, 2].iter().cloned().collect(); + /// let mut set_iter = set.iter(); + /// assert_eq!(set_iter.next(), Some(&1)); + /// assert_eq!(set_iter.next(), Some(&2)); + /// assert_eq!(set_iter.next(), Some(&3)); + /// assert_eq!(set_iter.next(), None); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn iter(&self) -> Iter { Iter { iter: self.map.keys() }