aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/collections/hash/set.rs
diff options
context:
space:
mode:
authorFenrir <[email protected]>2018-01-21 14:06:28 -0700
committerFenrirWolf <[email protected]>2018-01-21 19:16:33 -0700
commit23be3f4885688e5e0011005e2295c75168854c0a (patch)
treedd0850f9c73c489e114a761d5c0757f3dbec3a65 /ctr-std/src/collections/hash/set.rs
parentUpdate CI for Rust nightly-2017-12-01 + other fixes (diff)
downloadarchived-ctru-rs-23be3f4885688e5e0011005e2295c75168854c0a.tar.xz
archived-ctru-rs-23be3f4885688e5e0011005e2295c75168854c0a.zip
Recreate ctr-std from latest nightly
Diffstat (limited to 'ctr-std/src/collections/hash/set.rs')
-rw-r--r--ctr-std/src/collections/hash/set.rs53
1 files changed, 39 insertions, 14 deletions
diff --git a/ctr-std/src/collections/hash/set.rs b/ctr-std/src/collections/hash/set.rs
index 51698ce..e9427fb 100644
--- a/ctr-std/src/collections/hash/set.rs
+++ b/ctr-std/src/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")]
@@ -1152,13 +1185,9 @@ impl<'a, T, S> Iterator for Intersection<'a, T, S>
fn next(&mut self) -> Option<&'a T> {
loop {
- match self.iter.next() {
- None => return None,
- Some(elt) => {
- if self.other.contains(elt) {
- return Some(elt);
- }
- }
+ let elt = self.iter.next()?;
+ if self.other.contains(elt) {
+ return Some(elt);
}
}
}
@@ -1202,13 +1231,9 @@ impl<'a, T, S> Iterator for Difference<'a, T, S>
fn next(&mut self) -> Option<&'a T> {
loop {
- match self.iter.next() {
- None => return None,
- Some(elt) => {
- if !self.other.contains(elt) {
- return Some(elt);
- }
- }
+ let elt = self.iter.next()?;
+ if !self.other.contains(elt) {
+ return Some(elt);
}
}
}