Skip to content

Commit d9df296

Browse files
committed
Add doc example for HashSet::drain.
1 parent 34c1bfb commit d9df296

File tree

1 file changed

+16
-0
lines changed
  • src/libstd/collections/hash

1 file changed

+16
-0
lines changed

src/libstd/collections/hash/set.rs

+16
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,22 @@ impl<T, S> HashSet<T, S>
453453
}
454454

455455
/// Clears the set, returning all elements in an iterator.
456+
///
457+
/// # Examples
458+
///
459+
/// ```
460+
/// use std::collections::HashSet;
461+
///
462+
/// let mut set: HashSet<_> = [1, 2, 3].iter().cloned().collect();
463+
/// assert!(!set.is_empty());
464+
///
465+
/// // print 1, 2, 3 in an arbitrary order
466+
/// for i in set.drain() {
467+
/// println!("{}", i);
468+
/// }
469+
///
470+
/// assert!(set.is_empty());
471+
/// ```
456472
#[inline]
457473
#[stable(feature = "drain", since = "1.6.0")]
458474
pub fn drain(&mut self) -> Drain<T> {

0 commit comments

Comments
 (0)