diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2016-03-10 14:01:53 +0300 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2016-03-10 14:01:53 +0300 |
| commit | d6c4b53df1ee7ff1eff343224d502169566b03cc (patch) | |
| tree | 390d94262a2872e6d03127cf303e717ef24f9270 /src/libcollections | |
| parent | 3820d38e90127c9542d11a5677a2a0ec7804aacb (diff) | |
| parent | 99eee832e035895e62d0ac52608e63199d80a35a (diff) | |
| download | rust-d6c4b53df1ee7ff1eff343224d502169566b03cc.tar.gz rust-d6c4b53df1ee7ff1eff343224d502169566b03cc.zip | |
Rollup merge of #32136 - nathankleyn:improve-docs-for-btreeset, r=steveklabnik
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. r? @steveklabnik
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/btree/set.rs | 30 |
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> { |
