Skip to content

Commit

Permalink
Write examples for {BTree,Hash}Set::{get,replace,take}
Browse files Browse the repository at this point in the history
  • Loading branch information
Stjepan Glavina committed Jan 5, 2018
1 parent c1f4d47 commit d91c515
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,16 @@ impl<T, S> HashSet<T, S>
/// [`Hash`] and [`Eq`] on the borrowed form *must* match those for
/// the value type.
///
/// # Examples
///
/// ```
/// use std::collections::HashSet;
///
/// let set: HashSet<_> = [1, 2, 3].iter().cloned().collect();
/// assert_eq!(set.get(&2), Some(&2));
/// assert_eq!(set.get(&4), None);
/// ```
///
/// [`Eq`]: ../../std/cmp/trait.Eq.html
/// [`Hash`]: ../../std/hash/trait.Hash.html
#[stable(feature = "set_recovery", since = "1.9.0")]
Expand Down Expand Up @@ -631,6 +641,19 @@ impl<T, S> HashSet<T, S>

/// Adds a value to the set, replacing the existing value, if any, that is equal to the given
/// one. Returns the replaced value.
///
/// # Examples
///
/// ```
/// use std::collections::HashSet;
///
/// let mut set = HashSet::new();
/// set.insert(Vec::<i32>::new());
///
/// assert_eq!(set.get(&[][..]).unwrap().capacity(), 0);
/// set.replace(Vec::with_capacity(10));
/// assert_eq!(set.get(&[][..]).unwrap().capacity(), 10);
/// ```
#[stable(feature = "set_recovery", since = "1.9.0")]
pub fn replace(&mut self, value: T) -> Option<T> {
Recover::replace(&mut self.map, value)
Expand Down Expand Up @@ -671,6 +694,16 @@ impl<T, S> HashSet<T, S>
/// [`Hash`] and [`Eq`] on the borrowed form *must* match those for
/// the value type.
///
/// # Examples
///
/// ```
/// use std::collections::HashSet;
///
/// let mut set: HashSet<_> = [1, 2, 3].iter().cloned().collect();
/// assert_eq!(set.take(&2), Some(2));
/// assert_eq!(set.take(&2), None);
/// ```
///
/// [`Eq`]: ../../std/cmp/trait.Eq.html
/// [`Hash`]: ../../std/hash/trait.Hash.html
#[stable(feature = "set_recovery", since = "1.9.0")]
Expand Down

0 comments on commit d91c515

Please sign in to comment.