Skip to content

Commit 3577555

Browse files
committed
Implement AsRef and AsMut for fixed-sized arrays
1 parent ed81038 commit 3577555

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/libcore/array.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use clone::Clone;
2020
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
21+
use convert::{AsRef, AsMut};
2122
use fmt;
2223
use hash::{Hash, self};
2324
use iter::IntoIterator;
@@ -53,6 +54,24 @@ macro_rules! array_impls {
5354
}
5455
}
5556

57+
#[unstable(feature = "array_as_ref",
58+
reason = "should ideally be implemented for all fixed-sized arrays")]
59+
impl<T> AsRef<[T]> for [T; $N] {
60+
#[inline]
61+
fn as_ref(&self) -> &[T] {
62+
&self[..]
63+
}
64+
}
65+
66+
#[unstable(feature = "array_as_ref",
67+
reason = "should ideally be implemented for all fixed-sized arrays")]
68+
impl<T> AsMut<[T]> for [T; $N] {
69+
#[inline]
70+
fn as_mut(&mut self) -> &mut [T] {
71+
&mut self[..]
72+
}
73+
}
74+
5675
#[stable(feature = "rust1", since = "1.0.0")]
5776
impl<T:Copy> Clone for [T; $N] {
5877
fn clone(&self) -> [T; $N] {

0 commit comments

Comments
 (0)