mirror of https://github.com/rust-lang/rust.git
Rollup merge of #128261 - clarfonthey:iter-default, r=dtolnay
impl `Default` for collection iterators that don't already have it There is a pretty strong precedent for implementing `Default` for collection iterators, and this does so for some where this implementation was missed. I don't think this needs a separate ACP (since this precedent already exists, and these feel like they were just missed), however, it *will* need an FCP since these implementations are instantly stable.
This commit is contained in:
commit
2ee9678338
|
@ -1433,6 +1433,20 @@ pub struct Iter<'a, T: 'a> {
|
|||
iter: slice::Iter<'a, T>,
|
||||
}
|
||||
|
||||
#[stable(feature = "default_iters_sequel", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T> Default for Iter<'_, T> {
|
||||
/// Creates an empty `binary_heap::Iter`.
|
||||
///
|
||||
/// ```
|
||||
/// # use std::collections::binary_heap;
|
||||
/// let iter: binary_heap::Iter<'_, u8> = Default::default();
|
||||
/// assert_eq!(iter.len(), 0);
|
||||
/// ```
|
||||
fn default() -> Self {
|
||||
Iter { iter: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "collection_debug", since = "1.17.0")]
|
||||
impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
|
|
@ -2016,6 +2016,20 @@ impl<K, V> Default for Range<'_, K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "default_iters_sequel", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<K, V> Default for RangeMut<'_, K, V> {
|
||||
/// Creates an empty `btree_map::RangeMut`.
|
||||
///
|
||||
/// ```
|
||||
/// # use std::collections::btree_map;
|
||||
/// let iter: btree_map::RangeMut<'_, u8, u8> = Default::default();
|
||||
/// assert_eq!(iter.count(), 0);
|
||||
/// ```
|
||||
fn default() -> Self {
|
||||
RangeMut { inner: Default::default(), _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "map_values_mut", since = "1.10.0")]
|
||||
impl<'a, K, V> Iterator for ValuesMut<'a, K, V> {
|
||||
type Item = &'a mut V;
|
||||
|
@ -2050,6 +2064,20 @@ impl<K, V> ExactSizeIterator for ValuesMut<'_, K, V> {
|
|||
#[stable(feature = "fused", since = "1.26.0")]
|
||||
impl<K, V> FusedIterator for ValuesMut<'_, K, V> {}
|
||||
|
||||
#[stable(feature = "default_iters_sequel", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<K, V> Default for ValuesMut<'_, K, V> {
|
||||
/// Creates an empty `btree_map::ValuesMut`.
|
||||
///
|
||||
/// ```
|
||||
/// # use std::collections::btree_map;
|
||||
/// let iter: btree_map::ValuesMut<'_, u8, u8> = Default::default();
|
||||
/// assert_eq!(iter.count(), 0);
|
||||
/// ```
|
||||
fn default() -> Self {
|
||||
ValuesMut { inner: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "map_into_keys_values", since = "1.54.0")]
|
||||
impl<K, V, A: Allocator + Clone> Iterator for IntoKeys<K, V, A> {
|
||||
type Item = K;
|
||||
|
|
|
@ -28,6 +28,20 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "default_iters_sequel", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T> Default for Iter<'_, T> {
|
||||
/// Creates an empty `vec_deque::Iter`.
|
||||
///
|
||||
/// ```
|
||||
/// # use std::collections::vec_deque;
|
||||
/// let iter: vec_deque::Iter<'_, u8> = Default::default();
|
||||
/// assert_eq!(iter.len(), 0);
|
||||
/// ```
|
||||
fn default() -> Self {
|
||||
Iter { i1: Default::default(), i2: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> Clone for Iter<'_, T> {
|
||||
|
|
|
@ -28,6 +28,20 @@ impl<T: fmt::Debug> fmt::Debug for IterMut<'_, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "default_iters_sequel", since = "CURRENT_RUSTC_VERSION")]
|
||||
impl<T> Default for IterMut<'_, T> {
|
||||
/// Creates an empty `vec_deque::IterMut`.
|
||||
///
|
||||
/// ```
|
||||
/// # use std::collections::vec_deque;
|
||||
/// let iter: vec_deque::IterMut<'_, u8> = Default::default();
|
||||
/// assert_eq!(iter.len(), 0);
|
||||
/// ```
|
||||
fn default() -> Self {
|
||||
IterMut { i1: Default::default(), i2: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, T> Iterator for IterMut<'a, T> {
|
||||
type Item = &'a mut T;
|
||||
|
|
Loading…
Reference in New Issue