@@ -362,6 +362,20 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Iter<'_, K, V> {
362362 }
363363}
364364
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+
365379/// A mutable iterator over the entries of a `BTreeMap`.
366380///
367381/// 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> {
386400 }
387401}
388402
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+
389417/// An owning iterator over the entries of a `BTreeMap`.
390418///
391419/// 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> {
421449 }
422450}
423451
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+
424469/// An iterator over the keys of a `BTreeMap`.
425470///
426471/// This `struct` is created by the [`keys`] method on [`BTreeMap`]. See its
@@ -1768,6 +1813,20 @@ impl<K, V> Clone for Keys<'_, K, V> {
17681813 }
17691814}
17701815
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+
17711830#[ stable( feature = "rust1" , since = "1.0.0" ) ]
17721831impl < ' a , K , V > Iterator for Values < ' a , K , V > {
17731832 type Item = & ' a V ;
@@ -1809,6 +1868,20 @@ impl<K, V> Clone for Values<'_, K, V> {
18091868 }
18101869}
18111870
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+
18121885/// An iterator produced by calling `drain_filter` on BTreeMap.
18131886#[ unstable( feature = "btree_drain_filter" , issue = "70530" ) ]
18141887pub struct DrainFilter <
@@ -1945,6 +2018,20 @@ impl<'a, K, V> Iterator for Range<'a, K, V> {
19452018 }
19462019}
19472020
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+
19482035#[ stable( feature = "map_values_mut" , since = "1.10.0" ) ]
19492036impl < ' a , K , V > Iterator for ValuesMut < ' a , K , V > {
19502037 type Item = & ' a mut V ;
@@ -2021,6 +2108,23 @@ impl<K, V, A: Allocator + Clone> ExactSizeIterator for IntoKeys<K, V, A> {
20212108#[ stable( feature = "map_into_keys_values" , since = "1.54.0" ) ]
20222109impl < K , V , A : Allocator + Clone > FusedIterator for IntoKeys < K , V , A > { }
20232110
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+
20242128#[ stable( feature = "map_into_keys_values" , since = "1.54.0" ) ]
20252129impl < K , V , A : Allocator + Clone > Iterator for IntoValues < K , V , A > {
20262130 type Item = V ;
@@ -2055,6 +2159,23 @@ impl<K, V, A: Allocator + Clone> ExactSizeIterator for IntoValues<K, V, A> {
20552159#[ stable( feature = "map_into_keys_values" , since = "1.54.0" ) ]
20562160impl < K , V , A : Allocator + Clone > FusedIterator for IntoValues < K , V , A > { }
20572161
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+
20582179#[ stable( feature = "btree_range" , since = "1.17.0" ) ]
20592180impl < ' a , K , V > DoubleEndedIterator for Range < ' a , K , V > {
20602181 fn next_back ( & mut self ) -> Option < ( & ' a K , & ' a V ) > {
0 commit comments