@@ -993,7 +993,37 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
993
993
///
994
994
/// # Examples
995
995
///
996
- /// TODO
996
+ /// ```
997
+ /// #![feature(btree_set_entry)]
998
+ ///
999
+ /// use std::collections::BTreeSet;
1000
+ /// use std::collections::btree_set::Entry::*;
1001
+ ///
1002
+ /// let mut singles = BTreeSet::new();
1003
+ /// let mut dupes = BTreeSet::new();
1004
+ ///
1005
+ /// for ch in "a short treatise on fungi".chars() {
1006
+ /// if let Vacant(dupe_entry) = dupes.entry(ch) {
1007
+ /// // We haven't already seen a duplicate, so
1008
+ /// // check if we've at least seen it once.
1009
+ /// match singles.entry(ch) {
1010
+ /// Vacant(single_entry) => {
1011
+ /// // We found a new character for the first time.
1012
+ /// single_entry.insert()
1013
+ /// }
1014
+ /// Occupied(single_entry) => {
1015
+ /// // We've already seen this once, "move" it to dupes.
1016
+ /// single_entry.remove();
1017
+ /// dupe_entry.insert();
1018
+ /// }
1019
+ /// }
1020
+ /// }
1021
+ /// }
1022
+ ///
1023
+ /// assert!(!singles.contains(&'t') && dupes.contains(&'t'));
1024
+ /// assert!(singles.contains(&'u') && !dupes.contains(&'u'));
1025
+ /// assert!(!singles.contains(&'v') && !dupes.contains(&'v'));
1026
+ /// ```
997
1027
#[ inline]
998
1028
#[ unstable( feature = "btree_set_entry" , issue = "133549" ) ]
999
1029
pub fn entry ( & mut self , value : T ) -> Entry < ' _ , T , A >
0 commit comments