Implement AsRef and AsMut for fixed-sized arrays
This commit is contained in:
parent
ed81038504
commit
3577555742
@ -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] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user