@@ -362,6 +362,20 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Iter<'_, K, V> {
362
362
}
363
363
}
364
364
365
+ #[ stable( feature = "default_iters" , since = "CURRENT_RUSTC_VERSION" ) ]
366
+ impl < ' a , K : ' a , V : ' a > Default for Iter < ' a , K , V > {
367
+ /// Creates an empty `btree_map::Iter`.
368
+ ///
369
+ /// ```
370
+ /// # use std::collections::btree_map;
371
+ /// let iter: btree_map::Iter<'_, u8, u8> = Default::default();
372
+ /// assert_eq!(iter.len(), 0);
373
+ /// ```
374
+ fn default ( ) -> Self {
375
+ Iter { range : Default :: default ( ) , length : 0 }
376
+ }
377
+ }
378
+
365
379
/// A mutable iterator over the entries of a `BTreeMap`.
366
380
///
367
381
/// This `struct` is created by the [`iter_mut`] method on [`BTreeMap`]. See its
@@ -386,6 +400,20 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IterMut<'_, K, V> {
386
400
}
387
401
}
388
402
403
+ #[ stable( feature = "default_iters" , since = "CURRENT_RUSTC_VERSION" ) ]
404
+ impl < ' a , K : ' a , V : ' a > Default for IterMut < ' a , K , V > {
405
+ /// Creates an empty `btree_map::IterMut`.
406
+ ///
407
+ /// ```
408
+ /// # use std::collections::btree_map;
409
+ /// let iter: btree_map::IterMut<'_, u8, u8> = Default::default();
410
+ /// assert_eq!(iter.len(), 0);
411
+ /// ```
412
+ fn default ( ) -> Self {
413
+ IterMut { range : Default :: default ( ) , length : 0 , _marker : PhantomData { } }
414
+ }
415
+ }
416
+
389
417
/// An owning iterator over the entries of a `BTreeMap`.
390
418
///
391
419
/// This `struct` is created by the [`into_iter`] method on [`BTreeMap`]
@@ -421,6 +449,23 @@ impl<K: Debug, V: Debug, A: Allocator + Clone> Debug for IntoIter<K, V, A> {
421
449
}
422
450
}
423
451
452
+ #[ stable( feature = "default_iters" , since = "CURRENT_RUSTC_VERSION" ) ]
453
+ impl < K , V , A > Default for IntoIter < K , V , A >
454
+ where
455
+ A : Allocator + Default + Clone ,
456
+ {
457
+ /// Creates an empty `btree_map::IntoIter`.
458
+ ///
459
+ /// ```
460
+ /// # use std::collections::btree_map;
461
+ /// let iter: btree_map::IntoIter<u8, u8> = Default::default();
462
+ /// assert_eq!(iter.len(), 0);
463
+ /// ```
464
+ fn default ( ) -> Self {
465
+ IntoIter { range : Default :: default ( ) , length : 0 , alloc : Default :: default ( ) }
466
+ }
467
+ }
468
+
424
469
/// An iterator over the keys of a `BTreeMap`.
425
470
///
426
471
/// This `struct` is created by the [`keys`] method on [`BTreeMap`]. See its
@@ -1768,6 +1813,20 @@ impl<K, V> Clone for Keys<'_, K, V> {
1768
1813
}
1769
1814
}
1770
1815
1816
+ #[ stable( feature = "default_iters" , since = "CURRENT_RUSTC_VERSION" ) ]
1817
+ impl < K , V > Default for Keys < ' _ , K , V > {
1818
+ /// Creates an empty `btree_map::Keys`.
1819
+ ///
1820
+ /// ```
1821
+ /// # use std::collections::btree_map;
1822
+ /// let iter: btree_map::Keys<'_, u8, u8> = Default::default();
1823
+ /// assert_eq!(iter.len(), 0);
1824
+ /// ```
1825
+ fn default ( ) -> Self {
1826
+ Keys { inner : Default :: default ( ) }
1827
+ }
1828
+ }
1829
+
1771
1830
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1772
1831
impl < ' a , K , V > Iterator for Values < ' a , K , V > {
1773
1832
type Item = & ' a V ;
@@ -1809,6 +1868,20 @@ impl<K, V> Clone for Values<'_, K, V> {
1809
1868
}
1810
1869
}
1811
1870
1871
+ #[ stable( feature = "default_iters" , since = "CURRENT_RUSTC_VERSION" ) ]
1872
+ impl < K , V > Default for Values < ' _ , K , V > {
1873
+ /// Creates an empty `btree_map::Values`.
1874
+ ///
1875
+ /// ```
1876
+ /// # use std::collections::btree_map;
1877
+ /// let iter: btree_map::Values<'_, u8, u8> = Default::default();
1878
+ /// assert_eq!(iter.len(), 0);
1879
+ /// ```
1880
+ fn default ( ) -> Self {
1881
+ Values { inner : Default :: default ( ) }
1882
+ }
1883
+ }
1884
+
1812
1885
/// An iterator produced by calling `drain_filter` on BTreeMap.
1813
1886
#[ unstable( feature = "btree_drain_filter" , issue = "70530" ) ]
1814
1887
pub struct DrainFilter <
@@ -1945,6 +2018,20 @@ impl<'a, K, V> Iterator for Range<'a, K, V> {
1945
2018
}
1946
2019
}
1947
2020
2021
+ #[ stable( feature = "default_iters" , since = "CURRENT_RUSTC_VERSION" ) ]
2022
+ impl < K , V > Default for Range < ' _ , K , V > {
2023
+ /// Creates an empty `btree_map::Range`.
2024
+ ///
2025
+ /// ```
2026
+ /// # use std::collections::btree_map;
2027
+ /// let iter: btree_map::Range<'_, u8, u8> = Default::default();
2028
+ /// assert_eq!(iter.count(), 0);
2029
+ /// ```
2030
+ fn default ( ) -> Self {
2031
+ Range { inner : Default :: default ( ) }
2032
+ }
2033
+ }
2034
+
1948
2035
#[ stable( feature = "map_values_mut" , since = "1.10.0" ) ]
1949
2036
impl < ' a , K , V > Iterator for ValuesMut < ' a , K , V > {
1950
2037
type Item = & ' a mut V ;
@@ -2021,6 +2108,23 @@ impl<K, V, A: Allocator + Clone> ExactSizeIterator for IntoKeys<K, V, A> {
2021
2108
#[ stable( feature = "map_into_keys_values" , since = "1.54.0" ) ]
2022
2109
impl < K , V , A : Allocator + Clone > FusedIterator for IntoKeys < K , V , A > { }
2023
2110
2111
+ #[ stable( feature = "default_iters" , since = "CURRENT_RUSTC_VERSION" ) ]
2112
+ impl < K , V , A > Default for IntoKeys < K , V , A >
2113
+ where
2114
+ A : Allocator + Default + Clone ,
2115
+ {
2116
+ /// Creates an empty `btree_map::IntoKeys`.
2117
+ ///
2118
+ /// ```
2119
+ /// # use std::collections::btree_map;
2120
+ /// let iter: btree_map::IntoKeys<u8, u8> = Default::default();
2121
+ /// assert_eq!(iter.len(), 0);
2122
+ /// ```
2123
+ fn default ( ) -> Self {
2124
+ IntoKeys { inner : Default :: default ( ) }
2125
+ }
2126
+ }
2127
+
2024
2128
#[ stable( feature = "map_into_keys_values" , since = "1.54.0" ) ]
2025
2129
impl < K , V , A : Allocator + Clone > Iterator for IntoValues < K , V , A > {
2026
2130
type Item = V ;
@@ -2055,6 +2159,23 @@ impl<K, V, A: Allocator + Clone> ExactSizeIterator for IntoValues<K, V, A> {
2055
2159
#[ stable( feature = "map_into_keys_values" , since = "1.54.0" ) ]
2056
2160
impl < K , V , A : Allocator + Clone > FusedIterator for IntoValues < K , V , A > { }
2057
2161
2162
+ #[ stable( feature = "default_iters" , since = "CURRENT_RUSTC_VERSION" ) ]
2163
+ impl < K , V , A > Default for IntoValues < K , V , A >
2164
+ where
2165
+ A : Allocator + Default + Clone ,
2166
+ {
2167
+ /// Creates an empty `btree_map::IntoValues`.
2168
+ ///
2169
+ /// ```
2170
+ /// # use std::collections::btree_map;
2171
+ /// let iter: btree_map::IntoValues<u8, u8> = Default::default();
2172
+ /// assert_eq!(iter.len(), 0);
2173
+ /// ```
2174
+ fn default ( ) -> Self {
2175
+ IntoValues { inner : Default :: default ( ) }
2176
+ }
2177
+ }
2178
+
2058
2179
#[ stable( feature = "btree_range" , since = "1.17.0" ) ]
2059
2180
impl < ' a , K , V > DoubleEndedIterator for Range < ' a , K , V > {
2060
2181
fn next_back ( & mut self ) -> Option < ( & ' a K , & ' a V ) > {
0 commit comments