about summary refs log tree commit diff
path: root/src/libcore/array.rs
diff options
context:
space:
mode:
authorGleb Kozyrev <gleb@gkoz.com>2015-03-25 01:37:08 +0200
committerGleb Kozyrev <gleb@gkoz.com>2015-03-25 01:37:08 +0200
commit3577555742c0ebfa345a6a1c633f79bcc084a416 (patch)
tree6d03e4996d9a85b8407dfb6f72c8cf570e06fd92 /src/libcore/array.rs
parented810385045ab0db90303574ba3ea47dfa2a36d5 (diff)
downloadrust-3577555742c0ebfa345a6a1c633f79bcc084a416.tar.gz
rust-3577555742c0ebfa345a6a1c633f79bcc084a416.zip
Implement AsRef and AsMut for fixed-sized arrays
Diffstat (limited to 'src/libcore/array.rs')
-rw-r--r--src/libcore/array.rs19
1 files changed, 19 insertions, 0 deletions
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<T> 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<T> AsMut<[T]> for [T; $N] {
+                #[inline]
+                fn as_mut(&mut self) -> &mut [T] {
+                    &mut self[..]
+                }
+            }
+
             #[stable(feature = "rust1", since = "1.0.0")]
             impl<T:Copy> Clone for [T; $N] {
                 fn clone(&self) -> [T; $N] {