Add doc example for HashSet::drain.

This commit is contained in:
Corey Farwell 2017-08-01 08:12:01 -04:00
parent 34c1bfb0e1
commit d9df2963ad

View File

@ -453,6 +453,22 @@ pub fn is_empty(&self) -> bool {
}
/// Clears the set, returning all elements in an iterator.
///
/// # Examples
///
/// ```
/// use std::collections::HashSet;
///
/// let mut set: HashSet<_> = [1, 2, 3].iter().cloned().collect();
/// assert!(!set.is_empty());
///
/// // print 1, 2, 3 in an arbitrary order
/// for i in set.drain() {
/// println!("{}", i);
/// }
///
/// assert!(set.is_empty());
/// ```
#[inline]
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain(&mut self) -> Drain<T> {