about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNathan Kleyn <nathan@nathankleyn.com>2016-03-08 22:53:54 +0000
committerNathan Kleyn <nathan@nathankleyn.com>2016-03-08 22:53:54 +0000
commit99eee832e035895e62d0ac52608e63199d80a35a (patch)
tree3fdfb569ef636f1332e5e2c227ec692185fd919b
parent8f0479b2a5fc16814b68efe9e87dddf231b8941d (diff)
Add missing documentation examples for BTreeSet.
As part of the ongoing effort to document all methods with examples,
this commit adds the missing examples for the `BTreeSet` collection
type.

This is part of issue #29348.
-rw-r--r--src/libcollections/btree/set.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs
index 1cd50c2dcbe..dc653b446da 100644
--- a/src/libcollections/btree/set.rs
+++ b/src/libcollections/btree/set.rs
@@ -38,6 +38,36 @@ use Bound;
 /// [`Ord`]: ../../core/cmp/trait.Ord.html
 /// [`Cell`]: ../../std/cell/struct.Cell.html
 /// [`RefCell`]: ../../std/cell/struct.RefCell.html
+///
+/// # Examples
+///
+/// ```
+/// use std::collections::BTreeSet;
+///
+/// // Type inference lets us omit an explicit type signature (which
+/// // would be `BTreeSet<&str>` in this example).
+/// let mut books = BTreeSet::new();
+///
+/// // Add some books.
+/// books.insert("A Dance With Dragons");
+/// books.insert("To Kill a Mockingbird");
+/// books.insert("The Odyssey");
+/// books.insert("The Great Gatsby");
+///
+/// // Check for a specific one.
+/// if !books.contains("The Winds of Winter") {
+///     println!("We have {} books, but The Winds of Winter ain't one.",
+///              books.len());
+/// }
+///
+/// // Remove a book.
+/// books.remove("The Odyssey");
+///
+/// // Iterate over everything.
+/// for book in &books {
+///     println!("{}", book);
+/// }
+/// ```
 #[derive(Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct BTreeSet<T> {