Skip to content

Commit 8619b67

Browse files
committed
impl Default for Hash{Map,Set} iterators that don't already have it
1 parent feeba19 commit 8619b67

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

Diff for: library/std/src/collections/hash/map.rs

+64
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,14 @@ impl<K, V> Clone for Iter<'_, K, V> {
14041404
}
14051405
}
14061406

1407+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1408+
impl<K, V> Default for Iter<'_, K, V> {
1409+
#[inline]
1410+
fn default() -> Self {
1411+
Iter { base: Default::default() }
1412+
}
1413+
}
1414+
14071415
#[stable(feature = "std_debug", since = "1.16.0")]
14081416
impl<K: Debug, V: Debug> fmt::Debug for Iter<'_, K, V> {
14091417
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -1441,6 +1449,14 @@ impl<'a, K, V> IterMut<'a, K, V> {
14411449
}
14421450
}
14431451

1452+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1453+
impl<K, V> Default for IterMut<'_, K, V> {
1454+
#[inline]
1455+
fn default() -> Self {
1456+
IterMut { base: Default::default() }
1457+
}
1458+
}
1459+
14441460
/// An owning iterator over the entries of a `HashMap`.
14451461
///
14461462
/// This `struct` is created by the [`into_iter`] method on [`HashMap`]
@@ -1471,6 +1487,14 @@ impl<K, V> IntoIter<K, V> {
14711487
}
14721488
}
14731489

1490+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1491+
impl<K, V> Default for IntoIter<K, V> {
1492+
#[inline]
1493+
fn default() -> Self {
1494+
IntoIter { base: Default::default() }
1495+
}
1496+
}
1497+
14741498
/// An iterator over the keys of a `HashMap`.
14751499
///
14761500
/// This `struct` is created by the [`keys`] method on [`HashMap`]. See its
@@ -1502,6 +1526,14 @@ impl<K, V> Clone for Keys<'_, K, V> {
15021526
}
15031527
}
15041528

1529+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1530+
impl<K, V> Default for Keys<'_, K, V> {
1531+
#[inline]
1532+
fn default() -> Self {
1533+
Keys { inner: Default::default() }
1534+
}
1535+
}
1536+
15051537
#[stable(feature = "std_debug", since = "1.16.0")]
15061538
impl<K: Debug, V> fmt::Debug for Keys<'_, K, V> {
15071539
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -1540,6 +1572,14 @@ impl<K, V> Clone for Values<'_, K, V> {
15401572
}
15411573
}
15421574

1575+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1576+
impl<K, V> Default for Values<'_, K, V> {
1577+
#[inline]
1578+
fn default() -> Self {
1579+
Values { inner: Default::default() }
1580+
}
1581+
}
1582+
15431583
#[stable(feature = "std_debug", since = "1.16.0")]
15441584
impl<K, V: Debug> fmt::Debug for Values<'_, K, V> {
15451585
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -1626,6 +1666,14 @@ pub struct ValuesMut<'a, K: 'a, V: 'a> {
16261666
inner: IterMut<'a, K, V>,
16271667
}
16281668

1669+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1670+
impl<K, V> Default for ValuesMut<'_, K, V> {
1671+
#[inline]
1672+
fn default() -> Self {
1673+
ValuesMut { inner: Default::default() }
1674+
}
1675+
}
1676+
16291677
/// An owning iterator over the keys of a `HashMap`.
16301678
///
16311679
/// This `struct` is created by the [`into_keys`] method on [`HashMap`].
@@ -1648,6 +1696,14 @@ pub struct IntoKeys<K, V> {
16481696
inner: IntoIter<K, V>,
16491697
}
16501698

1699+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1700+
impl<K, V> Default for IntoKeys<K, V> {
1701+
#[inline]
1702+
fn default() -> Self {
1703+
IntoKeys { inner: Default::default() }
1704+
}
1705+
}
1706+
16511707
/// An owning iterator over the values of a `HashMap`.
16521708
///
16531709
/// This `struct` is created by the [`into_values`] method on [`HashMap`].
@@ -1670,6 +1726,14 @@ pub struct IntoValues<K, V> {
16701726
inner: IntoIter<K, V>,
16711727
}
16721728

1729+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1730+
impl<K, V> Default for IntoValues<K, V> {
1731+
#[inline]
1732+
fn default() -> Self {
1733+
IntoValues { inner: Default::default() }
1734+
}
1735+
}
1736+
16731737
/// A builder for computing where in a HashMap a key-value pair would be stored.
16741738
///
16751739
/// See the [`HashMap::raw_entry_mut`] docs for usage examples.

Diff for: library/std/src/collections/hash/set.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,14 @@ pub struct Iter<'a, K: 'a> {
12741274
base: base::Iter<'a, K>,
12751275
}
12761276

1277+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1278+
impl<K> Default for Iter<'_, K> {
1279+
#[inline]
1280+
fn default() -> Self {
1281+
Iter { base: Default::default() }
1282+
}
1283+
}
1284+
12771285
/// An owning iterator over the items of a `HashSet`.
12781286
///
12791287
/// This `struct` is created by the [`into_iter`] method on [`HashSet`]
@@ -1295,6 +1303,14 @@ pub struct IntoIter<K> {
12951303
base: base::IntoIter<K>,
12961304
}
12971305

1306+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1307+
impl<K> Default for IntoIter<K> {
1308+
#[inline]
1309+
fn default() -> Self {
1310+
IntoIter { base: Default::default() }
1311+
}
1312+
}
1313+
12981314
/// A draining iterator over the items of a `HashSet`.
12991315
///
13001316
/// This `struct` is created by the [`drain`] method on [`HashSet`].

0 commit comments

Comments
 (0)