Skip to content

Commit 11f738f

Browse files
committed
impl Default for Hash{Map,Set} iterators that don't already have it
1 parent ad9c494 commit 11f738f

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,14 @@ impl<K, V> Clone for Iter<'_, K, V> {
14381438
}
14391439
}
14401440

1441+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1442+
impl<K,V>DefaultforIter<'_,K,V>{
1443+
#[inline]
1444+
fndefault() -> Self{
1445+
Iter{base:Default::default()}
1446+
}
1447+
}
1448+
14411449
#[stable(feature = "std_debug", since = "1.16.0")]
14421450
impl<K:Debug,V:Debug> fmt::DebugforIter<'_,K,V>{
14431451
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
@@ -1476,6 +1484,14 @@ impl<'a, K, V> IterMut<'a, K, V> {
14761484
}
14771485
}
14781486

1487+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1488+
impl<K,V>DefaultforIterMut<'_,K,V>{
1489+
#[inline]
1490+
fndefault() -> Self{
1491+
IterMut{base:Default::default()}
1492+
}
1493+
}
1494+
14791495
/// An owning iterator over the entries of a `HashMap`.
14801496
///
14811497
/// This `struct` is created by the [`into_iter`] method on [`HashMap`]
@@ -1506,6 +1522,14 @@ impl<K, V> IntoIter<K, V> {
15061522
}
15071523
}
15081524

1525+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1526+
impl<K,V>DefaultforIntoIter<K,V>{
1527+
#[inline]
1528+
fndefault() -> Self{
1529+
IntoIter{base:Default::default()}
1530+
}
1531+
}
1532+
15091533
/// An iterator over the keys of a `HashMap`.
15101534
///
15111535
/// This `struct` is created by the [`keys`] method on [`HashMap`]. See its
@@ -1538,6 +1562,14 @@ impl<K, V> Clone for Keys<'_, K, V> {
15381562
}
15391563
}
15401564

1565+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1566+
impl<K,V>DefaultforKeys<'_,K,V>{
1567+
#[inline]
1568+
fndefault() -> Self{
1569+
Keys{inner:Default::default()}
1570+
}
1571+
}
1572+
15411573
#[stable(feature = "std_debug", since = "1.16.0")]
15421574
impl<K:Debug,V> fmt::DebugforKeys<'_,K,V>{
15431575
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
@@ -1577,6 +1609,14 @@ impl<K, V> Clone for Values<'_, K, V> {
15771609
}
15781610
}
15791611

1612+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1613+
impl<K,V>DefaultforValues<'_,K,V>{
1614+
#[inline]
1615+
fndefault() -> Self{
1616+
Values{inner:Default::default()}
1617+
}
1618+
}
1619+
15801620
#[stable(feature = "std_debug", since = "1.16.0")]
15811621
impl<K,V:Debug> fmt::DebugforValues<'_,K,V>{
15821622
fnfmt(&self,f:&mut fmt::Formatter<'_>) -> fmt::Result{
@@ -1665,6 +1705,14 @@ pub struct ValuesMut<'a, K: 'a, V: 'a> {
16651705
inner:IterMut<'a,K,V>,
16661706
}
16671707

1708+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1709+
impl<K,V>DefaultforValuesMut<'_,K,V>{
1710+
#[inline]
1711+
fndefault() -> Self{
1712+
ValuesMut{inner:Default::default()}
1713+
}
1714+
}
1715+
16681716
/// An owning iterator over the keys of a `HashMap`.
16691717
///
16701718
/// This `struct` is created by the [`into_keys`] method on [`HashMap`].
@@ -1687,6 +1735,14 @@ pub struct IntoKeys<K, V> {
16871735
inner:IntoIter<K,V>,
16881736
}
16891737

1738+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1739+
impl<K,V>DefaultforIntoKeys<K,V>{
1740+
#[inline]
1741+
fndefault() -> Self{
1742+
IntoKeys{inner:Default::default()}
1743+
}
1744+
}
1745+
16901746
/// An owning iterator over the values of a `HashMap`.
16911747
///
16921748
/// This `struct` is created by the [`into_values`] method on [`HashMap`].
@@ -1709,6 +1765,14 @@ pub struct IntoValues<K, V> {
17091765
inner:IntoIter<K,V>,
17101766
}
17111767

1768+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1769+
impl<K,V>DefaultforIntoValues<K,V>{
1770+
#[inline]
1771+
fndefault() -> Self{
1772+
IntoValues{inner:Default::default()}
1773+
}
1774+
}
1775+
17121776
/// A builder for computing where in a HashMap a key-value pair would be stored.
17131777
///
17141778
/// See the [`HashMap::raw_entry_mut`] docs for usage examples.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,14 @@ pub struct Iter<'a, K: 'a> {
12441244
base: base::Iter<'a,K>,
12451245
}
12461246

1247+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1248+
impl<K>DefaultforIter<'_,K>{
1249+
#[inline]
1250+
fndefault() -> Self{
1251+
Iter{base:Default::default()}
1252+
}
1253+
}
1254+
12471255
/// An owning iterator over the items of a `HashSet`.
12481256
///
12491257
/// This `struct` is created by the [`into_iter`] method on [`HashSet`]
@@ -1265,6 +1273,14 @@ pub struct IntoIter<K> {
12651273
base: base::IntoIter<K>,
12661274
}
12671275

1276+
#[stable(feature = "default_iters_hash", since = "CURRENT_RUSTC_VERSION")]
1277+
impl<K>DefaultforIntoIter<K>{
1278+
#[inline]
1279+
fndefault() -> Self{
1280+
IntoIter{base:Default::default()}
1281+
}
1282+
}
1283+
12681284
/// A draining iterator over the items of a `HashSet`.
12691285
///
12701286
/// This `struct` is created by the [`drain`] method on [`HashSet`].

0 commit comments

Comments
 (0)