From 7300daef727c29c6c48b1cec8968882b14eb1f25 Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Mon, 2 Sep 2024 03:49:35 +0300 Subject: [PATCH] impl `AsRef<[T; N]>` and `AsMut<[T; N]>` for `[T; N]` --- library/core/src/convert/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 432e55e8c9a4c..57e41bf73a16b 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -850,6 +850,24 @@ impl AsMut for str { } } +#[cfg(not(bootstrap))] +#[stable(feature = "array_as_ref_impl", since = "CURRENT_RUSTC_VERSION")] +impl AsRef<[T; N]> for [T; N] { + #[inline(always)] + fn as_ref(&self) -> &Self { + self + } +} + +#[cfg(not(bootstrap))] +#[stable(feature = "array_as_ref_impl", since = "CURRENT_RUSTC_VERSION")] +impl AsMut<[T; N]> for [T; N] { + #[inline(always)] + fn as_mut(&mut self) -> &mut Self { + self + } +} + //////////////////////////////////////////////////////////////////////////////// // THE NO-ERROR ERROR TYPE ////////////////////////////////////////////////////////////////////////////////