Skip to content

Commit 5926108

Browse files
committed
Rollup merge of rust-lang#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 rust-lang#29348. r? @steveklabnik
2 parents e85d9b1 + 99eee83 commit 5926108

File tree

1 file changed

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

1 file changed

+30
-0
lines changed

src/libcollections/btree/set.rs

+30
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,36 @@ use Bound;
3838
/// [`Ord`]: ../../core/cmp/trait.Ord.html
3939
/// [`Cell`]: ../../std/cell/struct.Cell.html
4040
/// [`RefCell`]: ../../std/cell/struct.RefCell.html
41+
///
42+
/// # Examples
43+
///
44+
/// ```
45+
/// use std::collections::BTreeSet;
46+
///
47+
/// // Type inference lets us omit an explicit type signature (which
48+
/// // would be `BTreeSet<&str>` in this example).
49+
/// let mut books = BTreeSet::new();
50+
///
51+
/// // Add some books.
52+
/// books.insert("A Dance With Dragons");
53+
/// books.insert("To Kill a Mockingbird");
54+
/// books.insert("The Odyssey");
55+
/// books.insert("The Great Gatsby");
56+
///
57+
/// // Check for a specific one.
58+
/// if !books.contains("The Winds of Winter") {
59+
/// println!("We have {} books, but The Winds of Winter ain't one.",
60+
/// books.len());
61+
/// }
62+
///
63+
/// // Remove a book.
64+
/// books.remove("The Odyssey");
65+
///
66+
/// // Iterate over everything.
67+
/// for book in &books {
68+
/// println!("{}", book);
69+
/// }
70+
/// ```
4171
#[derive(Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
4272
#[stable(feature = "rust1", since = "1.0.0")]
4373
pub struct BTreeSet<T> {

0 commit comments

Comments
 (0)