@@ -415,6 +415,16 @@ impl<T: Ord> BTreeSet<T> {
415
415
/// The value may be any borrowed form of the set's value type,
416
416
/// but the ordering on the borrowed form *must* match the
417
417
/// ordering on the value type.
418
+ ///
419
+ /// # Examples
420
+ ///
421
+ /// ```
422
+ /// use std::collections::BTreeSet;
423
+ ///
424
+ /// let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect();
425
+ /// assert_eq!(set.get(&2), Some(&2));
426
+ /// assert_eq!(set.get(&4), None);
427
+ /// ```
418
428
#[ stable( feature = "set_recovery" , since = "1.9.0" ) ]
419
429
pub fn get < Q : ?Sized > ( & self , value : & Q ) -> Option < & T >
420
430
where T : Borrow < Q > ,
@@ -540,6 +550,19 @@ impl<T: Ord> BTreeSet<T> {
540
550
541
551
/// Adds a value to the set, replacing the existing value, if any, that is equal to the given
542
552
/// one. Returns the replaced value.
553
+ ///
554
+ /// # Examples
555
+ ///
556
+ /// ```
557
+ /// use std::collections::BTreeSet;
558
+ ///
559
+ /// let mut set = BTreeSet::new();
560
+ /// set.insert(Vec::<i32>::new());
561
+ ///
562
+ /// assert_eq!(set.get(&[][..]).unwrap().capacity(), 0);
563
+ /// set.replace(Vec::with_capacity(10));
564
+ /// assert_eq!(set.get(&[][..]).unwrap().capacity(), 10);
565
+ /// ```
543
566
#[ stable( feature = "set_recovery" , since = "1.9.0" ) ]
544
567
pub fn replace ( & mut self , value : T ) -> Option < T > {
545
568
Recover :: replace ( & mut self . map , value)
@@ -576,6 +599,16 @@ impl<T: Ord> BTreeSet<T> {
576
599
/// The value may be any borrowed form of the set's value type,
577
600
/// but the ordering on the borrowed form *must* match the
578
601
/// ordering on the value type.
602
+ ///
603
+ /// # Examples
604
+ ///
605
+ /// ```
606
+ /// use std::collections::BTreeSet;
607
+ ///
608
+ /// let mut set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect();
609
+ /// assert_eq!(set.take(&2), Some(2));
610
+ /// assert_eq!(set.take(&2), None);
611
+ /// ```
579
612
#[ stable( feature = "set_recovery" , since = "1.9.0" ) ]
580
613
pub fn take < Q : ?Sized > ( & mut self , value : & Q ) -> Option < T >
581
614
where T : Borrow < Q > ,
0 commit comments