Skip to content

Commit 9ab95c3

Browse files
Rollup merge of #76917 - GuillaumeGomez:map-missing-code-examples, r=Dylan-DPC
Add missing code examples on HashMap types r? @Dylan-DPC
2 parents 623fb90 + be3d8e5 commit 9ab95c3

File tree

1 file changed

+106
-1
lines changed
  • library/std/src/collections/hash

1 file changed

+106
-1
lines changed

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

+106-1
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,16 @@ where
11021102
/// documentation for more.
11031103
///
11041104
/// [`iter`]: HashMap::iter
1105+
///
1106+
/// # Example
1107+
///
1108+
/// ```
1109+
/// use std::collections::HashMap;
1110+
///
1111+
/// let mut map = HashMap::new();
1112+
/// map.insert("a", 1);
1113+
/// let iter = map.iter();
1114+
/// ```
11051115
#[stable(feature = "rust1", since = "1.0.0")]
11061116
pub struct Iter<'a, K: 'a, V: 'a> {
11071117
base: base::Iter<'a, K, V>,
@@ -1129,6 +1139,16 @@ impl<K: Debug, V: Debug> fmt::Debug for Iter<'_, K, V> {
11291139
/// documentation for more.
11301140
///
11311141
/// [`iter_mut`]: HashMap::iter_mut
1142+
///
1143+
/// # Example
1144+
///
1145+
/// ```
1146+
/// use std::collections::HashMap;
1147+
///
1148+
/// let mut map = HashMap::new();
1149+
/// map.insert("a", 1);
1150+
/// let iter = map.iter_mut();
1151+
/// ```
11321152
#[stable(feature = "rust1", since = "1.0.0")]
11331153
pub struct IterMut<'a, K: 'a, V: 'a> {
11341154
base: base::IterMut<'a, K, V>,
@@ -1148,6 +1168,16 @@ impl<'a, K, V> IterMut<'a, K, V> {
11481168
/// (provided by the `IntoIterator` trait). See its documentation for more.
11491169
///
11501170
/// [`into_iter`]: IntoIterator::into_iter
1171+
///
1172+
/// # Example
1173+
///
1174+
/// ```
1175+
/// use std::collections::HashMap;
1176+
///
1177+
/// let mut map = HashMap::new();
1178+
/// map.insert("a", 1);
1179+
/// let iter = map.into_iter();
1180+
/// ```
11511181
#[stable(feature = "rust1", since = "1.0.0")]
11521182
pub struct IntoIter<K, V> {
11531183
base: base::IntoIter<K, V>,
@@ -1167,6 +1197,16 @@ impl<K, V> IntoIter<K, V> {
11671197
/// documentation for more.
11681198
///
11691199
/// [`keys`]: HashMap::keys
1200+
///
1201+
/// # Example
1202+
///
1203+
/// ```
1204+
/// use std::collections::HashMap;
1205+
///
1206+
/// let mut map = HashMap::new();
1207+
/// map.insert("a", 1);
1208+
/// let iter_keys = map.keys();
1209+
/// ```
11701210
#[stable(feature = "rust1", since = "1.0.0")]
11711211
pub struct Keys<'a, K: 'a, V: 'a> {
11721212
inner: Iter<'a, K, V>,
@@ -1194,6 +1234,16 @@ impl<K: Debug, V> fmt::Debug for Keys<'_, K, V> {
11941234
/// documentation for more.
11951235
///
11961236
/// [`values`]: HashMap::values
1237+
///
1238+
/// # Example
1239+
///
1240+
/// ```
1241+
/// use std::collections::HashMap;
1242+
///
1243+
/// let mut map = HashMap::new();
1244+
/// map.insert("a", 1);
1245+
/// let iter_values = map.values();
1246+
/// ```
11971247
#[stable(feature = "rust1", since = "1.0.0")]
11981248
pub struct Values<'a, K: 'a, V: 'a> {
11991249
inner: Iter<'a, K, V>,
@@ -1221,6 +1271,16 @@ impl<K, V: Debug> fmt::Debug for Values<'_, K, V> {
12211271
/// documentation for more.
12221272
///
12231273
/// [`drain`]: HashMap::drain
1274+
///
1275+
/// # Example
1276+
///
1277+
/// ```
1278+
/// use std::collections::HashMap;
1279+
///
1280+
/// let mut map = HashMap::new();
1281+
/// map.insert("a", 1);
1282+
/// let iter = map.drain();
1283+
/// ```
12241284
#[stable(feature = "drain", since = "1.6.0")]
12251285
pub struct Drain<'a, K: 'a, V: 'a> {
12261286
base: base::Drain<'a, K, V>,
@@ -1239,6 +1299,18 @@ impl<'a, K, V> Drain<'a, K, V> {
12391299
/// This `struct` is created by the [`drain_filter`] method on [`HashMap`].
12401300
///
12411301
/// [`drain_filter`]: HashMap::drain_filter
1302+
///
1303+
/// # Example
1304+
///
1305+
/// ```
1306+
/// #![feature(hash_drain_filter)]
1307+
///
1308+
/// use std::collections::HashMap;
1309+
///
1310+
/// let mut map = HashMap::new();
1311+
/// map.insert("a", 1);
1312+
/// let iter = map.drain_filter(|_k, v| *v % 2 == 0);
1313+
/// ```
12421314
#[unstable(feature = "hash_drain_filter", issue = "59618")]
12431315
pub struct DrainFilter<'a, K, V, F>
12441316
where
@@ -1253,6 +1325,16 @@ where
12531325
/// documentation for more.
12541326
///
12551327
/// [`values_mut`]: HashMap::values_mut
1328+
///
1329+
/// # Example
1330+
///
1331+
/// ```
1332+
/// use std::collections::HashMap;
1333+
///
1334+
/// let mut map = HashMap::new();
1335+
/// map.insert("a", 1);
1336+
/// let iter_values = map.values_mut();
1337+
/// ```
12561338
#[stable(feature = "map_values_mut", since = "1.10.0")]
12571339
pub struct ValuesMut<'a, K: 'a, V: 'a> {
12581340
inner: IterMut<'a, K, V>,
@@ -1264,6 +1346,18 @@ pub struct ValuesMut<'a, K: 'a, V: 'a> {
12641346
/// See its documentation for more.
12651347
///
12661348
/// [`into_keys`]: HashMap::into_keys
1349+
///
1350+
/// # Example
1351+
///
1352+
/// ```
1353+
/// #![feature(map_into_keys_values)]
1354+
///
1355+
/// use std::collections::HashMap;
1356+
///
1357+
/// let mut map = HashMap::new();
1358+
/// map.insert("a", 1);
1359+
/// let iter_keys = map.into_keys();
1360+
/// ```
12671361
#[unstable(feature = "map_into_keys_values", issue = "75294")]
12681362
pub struct IntoKeys<K, V> {
12691363
inner: IntoIter<K, V>,
@@ -1275,6 +1369,18 @@ pub struct IntoKeys<K, V> {
12751369
/// See its documentation for more.
12761370
///
12771371
/// [`into_values`]: HashMap::into_values
1372+
///
1373+
/// # Example
1374+
///
1375+
/// ```
1376+
/// #![feature(map_into_keys_values)]
1377+
///
1378+
/// use std::collections::HashMap;
1379+
///
1380+
/// let mut map = HashMap::new();
1381+
/// map.insert("a", 1);
1382+
/// let iter_keys = map.into_values();
1383+
/// ```
12781384
#[unstable(feature = "map_into_keys_values", issue = "75294")]
12791385
pub struct IntoValues<K, V> {
12801386
inner: IntoIter<K, V>,
@@ -1285,7 +1391,6 @@ pub struct IntoValues<K, V> {
12851391
/// See the [`HashMap::raw_entry_mut`] docs for usage examples.
12861392
///
12871393
/// [`HashMap::raw_entry_mut`]: HashMap::raw_entry_mut
1288-
12891394
#[unstable(feature = "hash_raw_entry", issue = "56167")]
12901395
pub struct RawEntryBuilderMut<'a, K: 'a, V: 'a, S: 'a> {
12911396
map: &'a mut HashMap<K, V, S>,

0 commit comments

Comments
 (0)