]> git.lizzy.rs Git - rust.git/commitdiff
Add `IntoIterator` impl `for [T; N]` (arrays by value)
authorLukas Kalbertodt <lukas.kalbertodt@gmail.com>
Fri, 25 Oct 2019 15:25:58 +0000 (17:25 +0200)
committerJosh Stone <jistone@redhat.com>
Fri, 16 Apr 2021 18:12:01 +0000 (11:12 -0700)
library/core/src/array/mod.rs

index b6ce825e2477a53eed05f3787137e61781d9ebd3..bd6f35edfac508d689fbc77379212083cf563af0 100644 (file)
@@ -155,6 +155,16 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
+#[stable(feature = "array_into_iter_impl", since = "1.53.0")]
+impl<T, const N: usize> IntoIterator for [T; N] {
+    type Item = T;
+    type IntoIter = IntoIter<T, N>;
+
+    fn into_iter(self) -> Self::IntoIter {
+        IntoIter::new(self)
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, T, const N: usize> IntoIterator for &'a [T; N] {
     type Item = &'a T;