Skip to content

Commit 9fc8394

Browse files
committed
auto merge of #15668 : steveklabnik/rust/tree_set_example, r=alexcrichton
Someone asked for an example usage of this on IRC, so I tossed together the simplest one. Obviously, this isn't up to snuff, but it's better than nothing.
2 parents 32cb44b + ace3a77 commit 9fc8394

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/libcollections/treemap.rs

+32
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
//! An ordered map and set implemented as self-balancing binary search
1212
//! trees. The only requirement for the types is that the key implements
1313
//! `Ord`.
14+
//!
15+
//! ## Example
16+
//!
17+
//! ```{rust}
18+
//! use std::collections::TreeSet;
19+
//!
20+
//! let mut tree_set = TreeSet::new();
21+
//!
22+
//! tree_set.insert(2i);
23+
//! tree_set.insert(1i);
24+
//! tree_set.insert(3i);
25+
//!
26+
//! for i in tree_set.iter() {
27+
//! println!("{}", i) // prints 1, then 2, then 3
28+
//! }
29+
//! ```
1430
1531
use core::prelude::*;
1632

@@ -587,6 +603,22 @@ impl<'a, T> Iterator<&'a T> for RevSetItems<'a, T> {
587603
/// A implementation of the `Set` trait on top of the `TreeMap` container. The
588604
/// only requirement is that the type of the elements contained ascribes to the
589605
/// `Ord` trait.
606+
///
607+
/// ## Example
608+
///
609+
/// ```{rust}
610+
/// use std::collections::TreeSet;
611+
///
612+
/// let mut tree_set = TreeSet::new();
613+
///
614+
/// tree_set.insert(2i);
615+
/// tree_set.insert(1i);
616+
/// tree_set.insert(3i);
617+
///
618+
/// for i in tree_set.iter() {
619+
/// println!("{}", i) // prints 1, then 2, then 3
620+
/// }
621+
/// ```
590622
#[deriving(Clone)]
591623
pub struct TreeSet<T> {
592624
map: TreeMap<T, ()>

0 commit comments

Comments
 (0)