diff options
| author | bors <bors@rust-lang.org> | 2023-03-25 06:29:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-25 06:29:46 +0000 |
| commit | 9fa6b3c15758e85657d5be051cfa57022a8bbe57 (patch) | |
| tree | 833bbcd08e49656c242961cf5e6de45eadca7fc0 /library/alloc/src/vec | |
| parent | 24a69af213f4bf23014dc91903e7a934c88f6b9e (diff) | |
| parent | e44836faf6ff114805062f723b349d6e10bf86b6 (diff) | |
| download | rust-9fa6b3c15758e85657d5be051cfa57022a8bbe57.tar.gz rust-9fa6b3c15758e85657d5be051cfa57022a8bbe57.zip | |
Auto merge of #99929 - the8472:default-iters, r=scottmcm
Implement Default for some alloc/core iterators
Add `Default` impls to the following collection iterators:
* slice::{Iter, IterMut}
* binary_heap::IntoIter
* btree::map::{Iter, IterMut, Keys, Values, Range, IntoIter, IntoKeys, IntoValues}
* btree::set::{Iter, IntoIter, Range}
* linked_list::IntoIter
* vec::IntoIter
and these adapters:
* adapters::{Chain, Cloned, Copied, Rev, Enumerate, Flatten, Fuse, Rev}
For iterators which are generic over allocators it only implements it for the global allocator because we can't conjure an allocator from nothing or would have to turn the allocator field into an `Option` just for this change.
These changes will be insta-stable.
ACP: https://github.com/rust-lang/libs-team/issues/77
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/into_iter.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 37966007eb7..f6525eb9003 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -347,6 +347,24 @@ impl<T, A: Allocator> FusedIterator for IntoIter<T, A> {} #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl<T, A: Allocator> TrustedLen for IntoIter<T, A> {} +#[stable(feature = "default_iters", since = "CURRENT_RUSTC_VERSION")] +impl<T, A> Default for IntoIter<T, A> +where + A: Allocator + Default, +{ + /// Creates an empty `vec::IntoIter`. + /// + /// ``` + /// # use std::vec; + /// let iter: vec::IntoIter<u8> = Default::default(); + /// assert_eq!(iter.len(), 0); + /// assert_eq!(iter.as_slice(), &[]); + /// ``` + fn default() -> Self { + super::Vec::new_in(Default::default()).into_iter() + } +} + #[doc(hidden)] #[unstable(issue = "none", feature = "std_internals")] #[rustc_unsafe_specialization_marker] |
