diff options
| author | kennytm <kennytm@gmail.com> | 2018-01-07 02:36:05 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-07 02:36:05 +0800 |
| commit | e7192c1a4b884ddeb54c32678da1687558d51e1f (patch) | |
| tree | 7fcd51dbf59636e31f972514f89aa369aca62361 /src/libstd | |
| parent | c6bf11cf2b68d104ec33f1bca033ce1e06be1fd1 (diff) | |
| parent | 7948f458ab28dc3476e764850a15f62f594609b1 (diff) | |
| download | rust-e7192c1a4b884ddeb54c32678da1687558d51e1f.tar.gz rust-e7192c1a4b884ddeb54c32678da1687558d51e1f.zip | |
Rollup merge of #47217 - stjepang:set-examples, r=frewsxcv
Write examples for {BTree,Hash}Set::{get,replace,take}
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 7f0e5a8d2aa..e9427fb40a0 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -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")] @@ -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) @@ -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")] |
