Skip to content

Commit 47b071a

Browse files
committed
Add doctests for iter and into_iter for BTreeSet.
1 parent 193390d commit 47b071a

File tree

1 file changed

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

1 file changed

+26
-0
lines changed

src/libcollections/btree/set.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,38 @@ impl<T: Ord> BTreeSet<T> {
8080

8181
impl<T> BTreeSet<T> {
8282
/// Gets an iterator over the BTreeSet's contents.
83+
///
84+
/// # Examples
85+
///
86+
/// ```
87+
/// use std::collections::BTreeSet;
88+
///
89+
/// let set: BTreeSet<uint> = [1u, 2, 3, 4].iter().map(|&x| x).collect();
90+
///
91+
/// for x in set.iter() {
92+
/// println!("{}", x);
93+
/// }
94+
///
95+
/// let v: Vec<uint> = set.iter().map(|&x| x).collect();
96+
/// assert_eq!(v, vec![1u,2,3,4]);
97+
/// ```
8398
#[unstable = "matches collection reform specification, waiting for dust to settle"]
8499
pub fn iter<'a>(&'a self) -> Items<'a, T> {
85100
self.map.keys()
86101
}
87102

88103
/// Gets an iterator for moving out the BtreeSet's contents.
104+
///
105+
/// # Examples
106+
///
107+
/// ```
108+
/// use std::collections::BTreeSet;
109+
///
110+
/// let set: BTreeSet<uint> = [1u, 2, 3, 4].iter().map(|&x| x).collect();
111+
///
112+
/// let v: Vec<uint> = set.into_iter().collect();
113+
/// assert_eq!(v, vec![1u,2,3,4]);
114+
/// ```
89115
#[unstable = "matches collection reform specification, waiting for dust to settle"]
90116
pub fn into_iter(self) -> MoveItems<T> {
91117
self.map.into_iter().map(|(k, _)| k)

0 commit comments

Comments
 (0)