Stabilize by-value [T; N] iterator core::array::IntoIter
Tracking issue: https://github.com/rust-lang/rust/issues/65798 This is unblocked now that `min_const_generics` has been stabilized in https://github.com/rust-lang/rust/pull/79135. This PR does *not* include the corresponding `IntoIterator` impl, which is https://github.com/rust-lang/rust/pull/65819. Instead, an iterator can be constructed through the `new` method. `new` would become unnecessary when `IntoIterator` is implemented and might be deprecated then, although it will stay stable.
This commit is contained in:
@@ -11,7 +11,7 @@ use crate::{
|
||||
/// A by-value [array] iterator.
|
||||
///
|
||||
/// [array]: ../../std/primitive.array.html
|
||||
#[unstable(feature = "array_value_iter", issue = "65798")]
|
||||
#[stable(feature = "array_value_iter", since = "1.51.0")]
|
||||
pub struct IntoIter<T, const N: usize> {
|
||||
/// This is the array we are iterating over.
|
||||
///
|
||||
@@ -38,10 +38,11 @@ pub struct IntoIter<T, const N: usize> {
|
||||
impl<T, const N: usize> IntoIter<T, N> {
|
||||
/// Creates a new iterator over the given `array`.
|
||||
///
|
||||
/// *Note*: this method might never get stabilized and/or removed in the
|
||||
/// future as there will likely be another, preferred way of obtaining this
|
||||
/// iterator (either via `IntoIterator` for arrays or via another way).
|
||||
#[unstable(feature = "array_value_iter", issue = "65798")]
|
||||
/// *Note*: this method might be deprecated in the future,
|
||||
/// after [`IntoIterator` is implemented for arrays][array-into-iter].
|
||||
///
|
||||
/// [array-into-iter]: https://github.com/rust-lang/rust/pull/65819
|
||||
#[stable(feature = "array_value_iter", since = "1.51.0")]
|
||||
pub fn new(array: [T; N]) -> Self {
|
||||
// SAFETY: The transmute here is actually safe. The docs of `MaybeUninit`
|
||||
// promise:
|
||||
@@ -69,7 +70,7 @@ impl<T, const N: usize> IntoIter<T, N> {
|
||||
|
||||
/// Returns an immutable slice of all elements that have not been yielded
|
||||
/// yet.
|
||||
#[unstable(feature = "array_value_iter_slice", issue = "65798")]
|
||||
#[stable(feature = "array_value_iter", since = "1.51.0")]
|
||||
pub fn as_slice(&self) -> &[T] {
|
||||
// SAFETY: We know that all elements within `alive` are properly initialized.
|
||||
unsafe {
|
||||
@@ -79,7 +80,7 @@ impl<T, const N: usize> IntoIter<T, N> {
|
||||
}
|
||||
|
||||
/// Returns a mutable slice of all elements that have not been yielded yet.
|
||||
#[unstable(feature = "array_value_iter_slice", issue = "65798")]
|
||||
#[stable(feature = "array_value_iter", since = "1.51.0")]
|
||||
pub fn as_mut_slice(&mut self) -> &mut [T] {
|
||||
// SAFETY: We know that all elements within `alive` are properly initialized.
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user