Skip to content

Commit 28588e5

Browse files
Add missing examples on HashSet iter types
1 parent 953f33c commit 28588e5

File tree

1 file changed

+86
-0
lines changed
  • library/std/src/collections/hash

1 file changed

+86
-0
lines changed

library/std/src/collections/hash/set.rs

+86
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,16 @@ where
11731173
/// See its documentation for more.
11741174
///
11751175
/// [`iter`]: HashSet::iter
1176+
///
1177+
/// # Examples
1178+
///
1179+
/// ```
1180+
/// use std::collections::HashSet;
1181+
///
1182+
/// let a: HashSet<u32> = vec![1, 2, 3].into_iter().collect();
1183+
///
1184+
/// let mut iter = a.iter();
1185+
/// ```
11761186
#[stable(feature = "rust1", since = "1.0.0")]
11771187
pub struct Iter<'a, K: 'a> {
11781188
base: base::Iter<'a, K>,
@@ -1184,6 +1194,16 @@ pub struct Iter<'a, K: 'a> {
11841194
/// (provided by the `IntoIterator` trait). See its documentation for more.
11851195
///
11861196
/// [`into_iter`]: IntoIterator::into_iter
1197+
///
1198+
/// # Examples
1199+
///
1200+
/// ```
1201+
/// use std::collections::HashSet;
1202+
///
1203+
/// let a: HashSet<u32> = vec![1, 2, 3].into_iter().collect();
1204+
///
1205+
/// let mut iter = a.into_iter();
1206+
/// ```
11871207
#[stable(feature = "rust1", since = "1.0.0")]
11881208
pub struct IntoIter<K> {
11891209
base: base::IntoIter<K>,
@@ -1195,6 +1215,16 @@ pub struct IntoIter<K> {
11951215
/// See its documentation for more.
11961216
///
11971217
/// [`drain`]: HashSet::drain
1218+
///
1219+
/// # Examples
1220+
///
1221+
/// ```
1222+
/// use std::collections::HashSet;
1223+
///
1224+
/// let mut a: HashSet<u32> = vec![1, 2, 3].into_iter().collect();
1225+
///
1226+
/// let mut drain = a.drain();
1227+
/// ```
11981228
#[stable(feature = "rust1", since = "1.0.0")]
11991229
pub struct Drain<'a, K: 'a> {
12001230
base: base::Drain<'a, K>,
@@ -1205,6 +1235,18 @@ pub struct Drain<'a, K: 'a> {
12051235
/// This `struct` is created by the [`drain_filter`] method on [`HashSet`].
12061236
///
12071237
/// [`drain_filter`]: HashSet::drain_filter
1238+
///
1239+
/// # Examples
1240+
///
1241+
/// ```
1242+
/// #![feature(hash_drain_filter)]
1243+
///
1244+
/// use std::collections::HashSet;
1245+
///
1246+
/// let mut a: HashSet<u32> = vec![1, 2, 3].into_iter().collect();
1247+
///
1248+
/// let mut drain_filtered = a.drain_filter(|v| v % 2 == 0);
1249+
/// ```
12081250
#[unstable(feature = "hash_drain_filter", issue = "59618")]
12091251
pub struct DrainFilter<'a, K, F>
12101252
where
@@ -1219,6 +1261,17 @@ where
12191261
/// See its documentation for more.
12201262
///
12211263
/// [`intersection`]: HashSet::intersection
1264+
///
1265+
/// # Examples
1266+
///
1267+
/// ```
1268+
/// use std::collections::HashSet;
1269+
///
1270+
/// let a: HashSet<u32> = vec![1, 2, 3].into_iter().collect();
1271+
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
1272+
///
1273+
/// let mut intersection = a.intersection(&b);
1274+
/// ```
12221275
#[stable(feature = "rust1", since = "1.0.0")]
12231276
pub struct Intersection<'a, T: 'a, S: 'a> {
12241277
// iterator of the first set
@@ -1233,6 +1286,17 @@ pub struct Intersection<'a, T: 'a, S: 'a> {
12331286
/// See its documentation for more.
12341287
///
12351288
/// [`difference`]: HashSet::difference
1289+
///
1290+
/// # Examples
1291+
///
1292+
/// ```
1293+
/// use std::collections::HashSet;
1294+
///
1295+
/// let a: HashSet<u32> = vec![1, 2, 3].into_iter().collect();
1296+
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
1297+
///
1298+
/// let mut difference = a.difference(&b);
1299+
/// ```
12361300
#[stable(feature = "rust1", since = "1.0.0")]
12371301
pub struct Difference<'a, T: 'a, S: 'a> {
12381302
// iterator of the first set
@@ -1247,6 +1311,17 @@ pub struct Difference<'a, T: 'a, S: 'a> {
12471311
/// [`HashSet`]. See its documentation for more.
12481312
///
12491313
/// [`symmetric_difference`]: HashSet::symmetric_difference
1314+
///
1315+
/// # Examples
1316+
///
1317+
/// ```
1318+
/// use std::collections::HashSet;
1319+
///
1320+
/// let a: HashSet<u32> = vec![1, 2, 3].into_iter().collect();
1321+
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
1322+
///
1323+
/// let mut intersection = a.symmetric_difference(&b);
1324+
/// ```
12501325
#[stable(feature = "rust1", since = "1.0.0")]
12511326
pub struct SymmetricDifference<'a, T: 'a, S: 'a> {
12521327
iter: Chain<Difference<'a, T, S>, Difference<'a, T, S>>,
@@ -1258,6 +1333,17 @@ pub struct SymmetricDifference<'a, T: 'a, S: 'a> {
12581333
/// See its documentation for more.
12591334
///
12601335
/// [`union`]: HashSet::union
1336+
///
1337+
/// # Examples
1338+
///
1339+
/// ```
1340+
/// use std::collections::HashSet;
1341+
///
1342+
/// let a: HashSet<u32> = vec![1, 2, 3].into_iter().collect();
1343+
/// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
1344+
///
1345+
/// let mut union_iter = a.union(&b);
1346+
/// ```
12611347
#[stable(feature = "rust1", since = "1.0.0")]
12621348
pub struct Union<'a, T: 'a, S: 'a> {
12631349
iter: Chain<Iter<'a, T>, Difference<'a, T, S>>,

0 commit comments

Comments
 (0)