From 3577555742c0ebfa345a6a1c633f79bcc084a416 Mon Sep 17 00:00:00 2001 From: Gleb Kozyrev Date: Wed, 25 Mar 2015 01:37:08 +0200 Subject: [PATCH] Implement AsRef and AsMut for fixed-sized arrays --- src/libcore/array.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libcore/array.rs b/src/libcore/array.rs index b2c23f051d5..91301ee558c 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -18,6 +18,7 @@ use clone::Clone; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; +use convert::{AsRef, AsMut}; use fmt; use hash::{Hash, self}; use iter::IntoIterator; @@ -53,6 +54,24 @@ macro_rules! array_impls { } } + #[unstable(feature = "array_as_ref", + reason = "should ideally be implemented for all fixed-sized arrays")] + impl AsRef<[T]> for [T; $N] { + #[inline] + fn as_ref(&self) -> &[T] { + &self[..] + } + } + + #[unstable(feature = "array_as_ref", + reason = "should ideally be implemented for all fixed-sized arrays")] + impl AsMut<[T]> for [T; $N] { + #[inline] + fn as_mut(&mut self) -> &mut [T] { + &mut self[..] + } + } + #[stable(feature = "rust1", since = "1.0.0")] impl Clone for [T; $N] { fn clone(&self) -> [T; $N] {