2014-11-14 12:37:59 +01:00
|
|
|
//! Implementations of things like `Eq` for fixed-length arrays
|
|
|
|
//! up to a certain length. Eventually we should able to generalize
|
|
|
|
//! to all lengths.
|
2015-07-20 11:21:02 -07:00
|
|
|
//!
|
2016-03-01 20:44:48 +08:00
|
|
|
//! *[See also the array primitive type](../../std/primitive.array.html).*
|
2014-10-31 05:41:25 -04:00
|
|
|
|
2019-05-09 11:58:39 +09:00
|
|
|
#![stable(feature = "core_array", since = "1.36.0")]
|
2015-03-23 14:01:28 -07:00
|
|
|
|
2019-04-15 11:23:21 +09:00
|
|
|
use crate::borrow::{Borrow, BorrowMut};
|
|
|
|
use crate::cmp::Ordering;
|
2019-04-26 12:45:26 -07:00
|
|
|
use crate::convert::{Infallible, TryFrom};
|
2019-04-15 11:23:21 +09:00
|
|
|
use crate::fmt;
|
|
|
|
use crate::hash::{Hash, self};
|
|
|
|
use crate::marker::Unsize;
|
|
|
|
use crate::slice::{Iter, IterMut};
|
2014-10-31 05:41:25 -04:00
|
|
|
|
2015-02-27 22:48:51 +03:00
|
|
|
/// Utility trait implemented only on arrays of fixed size
|
|
|
|
///
|
|
|
|
/// This trait can be used to implement other traits on fixed-size arrays
|
|
|
|
/// without causing much metadata bloat.
|
2015-09-23 11:38:01 -04:00
|
|
|
///
|
|
|
|
/// The trait is marked unsafe in order to restrict implementors to fixed-size
|
|
|
|
/// arrays. User of this trait can assume that implementors have the exact
|
|
|
|
/// layout in memory of a fixed size array (for example, for unsafe
|
|
|
|
/// initialization).
|
|
|
|
///
|
|
|
|
/// Note that the traits AsRef and AsMut provide similar methods for types that
|
|
|
|
/// may not be fixed-size arrays. Implementors should prefer those traits
|
|
|
|
/// instead.
|
2019-05-09 11:58:39 +09:00
|
|
|
#[unstable(feature = "fixed_size_array", issue = "27778")]
|
2015-09-19 15:33:34 -04:00
|
|
|
pub unsafe trait FixedSizeArray<T> {
|
2015-02-27 22:48:51 +03:00
|
|
|
/// Converts the array to immutable slice
|
2019-05-09 11:58:39 +09:00
|
|
|
#[unstable(feature = "fixed_size_array", issue = "27778")]
|
2015-02-27 22:48:51 +03:00
|
|
|
fn as_slice(&self) -> &[T];
|
|
|
|
/// Converts the array to mutable slice
|
2019-05-09 11:58:39 +09:00
|
|
|
#[unstable(feature = "fixed_size_array", issue = "27778")]
|
2015-02-27 22:48:51 +03:00
|
|
|
fn as_mut_slice(&mut self) -> &mut [T];
|
|
|
|
}
|
|
|
|
|
2019-05-09 11:58:39 +09:00
|
|
|
#[unstable(feature = "fixed_size_array", issue = "27778")]
|
2015-09-19 15:33:34 -04:00
|
|
|
unsafe impl<T, A: Unsize<[T]>> FixedSizeArray<T> for A {
|
2015-08-29 18:30:05 +02:00
|
|
|
#[inline]
|
|
|
|
fn as_slice(&self) -> &[T] {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn as_mut_slice(&mut self) -> &mut [T] {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 16:35:23 -04:00
|
|
|
/// The error type returned when a conversion from a slice to an array fails.
|
2019-02-08 15:00:47 +01:00
|
|
|
#[stable(feature = "try_from", since = "1.34.0")]
|
2017-09-21 16:35:23 -04:00
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct TryFromSliceError(());
|
|
|
|
|
2019-05-09 11:58:39 +09:00
|
|
|
#[stable(feature = "core_array", since = "1.36.0")]
|
2017-09-29 11:15:05 -04:00
|
|
|
impl fmt::Display for TryFromSliceError {
|
|
|
|
#[inline]
|
2019-04-19 01:37:12 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2017-09-29 11:26:19 -04:00
|
|
|
fmt::Display::fmt(self.__description(), f)
|
2017-09-29 11:15:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFromSliceError {
|
2017-09-29 11:20:21 -04:00
|
|
|
#[unstable(feature = "array_error_internals",
|
|
|
|
reason = "available through Error trait and this method should not \
|
|
|
|
be exposed publicly",
|
|
|
|
issue = "0")]
|
2017-09-29 11:15:05 -04:00
|
|
|
#[inline]
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub fn __description(&self) -> &str {
|
|
|
|
"could not convert slice to array"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-26 12:45:26 -07:00
|
|
|
#[stable(feature = "try_from_slice_error", since = "1.36.0")]
|
|
|
|
impl From<Infallible> for TryFromSliceError {
|
|
|
|
fn from(x: Infallible) -> TryFromSliceError {
|
|
|
|
match x {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<T, const N: usize> AsRef<[T]> for [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn as_ref(&self) -> &[T] {
|
|
|
|
&self[..]
|
2015-12-02 17:31:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<T, const N: usize> AsMut<[T]> for [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn as_mut(&mut self) -> &mut [T] {
|
|
|
|
&mut self[..]
|
2015-12-02 17:31:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "array_borrow", since = "1.4.0")]
|
|
|
|
impl<T, const N: usize> Borrow<[T]> for [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
fn borrow(&self) -> &[T] {
|
|
|
|
self
|
2014-10-31 05:41:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "array_borrow", since = "1.4.0")]
|
|
|
|
impl<T, const N: usize> BorrowMut<[T]> for [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
fn borrow_mut(&mut self) -> &mut [T] {
|
|
|
|
self
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "try_from", since = "1.34.0")]
|
|
|
|
impl<T, const N: usize> TryFrom<&[T]> for [T; N]
|
|
|
|
where
|
|
|
|
T: Copy,
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
type Error = TryFromSliceError;
|
|
|
|
|
|
|
|
fn try_from(slice: &[T]) -> Result<[T; N], TryFromSliceError> {
|
|
|
|
<&Self>::try_from(slice).map(|r| *r)
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "try_from", since = "1.34.0")]
|
|
|
|
impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
type Error = TryFromSliceError;
|
|
|
|
|
|
|
|
fn try_from(slice: &[T]) -> Result<&[T; N], TryFromSliceError> {
|
|
|
|
if slice.len() == N {
|
|
|
|
let ptr = slice.as_ptr() as *const [T; N];
|
|
|
|
unsafe { Ok(&*ptr) }
|
|
|
|
} else {
|
|
|
|
Err(TryFromSliceError(()))
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "try_from", since = "1.34.0")]
|
|
|
|
impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
type Error = TryFromSliceError;
|
|
|
|
|
|
|
|
fn try_from(slice: &mut [T]) -> Result<&mut [T; N], TryFromSliceError> {
|
|
|
|
if slice.len() == N {
|
|
|
|
let ptr = slice.as_mut_ptr() as *mut [T; N];
|
|
|
|
unsafe { Ok(&mut *ptr) }
|
|
|
|
} else {
|
|
|
|
Err(TryFromSliceError(()))
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<T: Hash, const N: usize> Hash for [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
|
|
|
Hash::hash(&self[..], state)
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<T: fmt::Debug, const N: usize> fmt::Debug for [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
fmt::Debug::fmt(&&self[..], f)
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<'a, T, const N: usize> IntoIterator for &'a [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
type Item = &'a T;
|
|
|
|
type IntoIter = Iter<'a, T>;
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
fn into_iter(self) -> Iter<'a, T> {
|
|
|
|
self.iter()
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<'a, T, const N: usize> IntoIterator for &'a mut [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
type Item = &'a mut T;
|
|
|
|
type IntoIter = IterMut<'a, T>;
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
fn into_iter(self) -> IterMut<'a, T> {
|
|
|
|
self.iter_mut()
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<'a, 'b, A, B, const N: usize> PartialEq<[B; N]> for [A; N]
|
|
|
|
where
|
|
|
|
A: PartialEq<B>,
|
|
|
|
[A; N]: LengthAtMost32,
|
|
|
|
[B; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &[B; N]) -> bool {
|
|
|
|
self[..] == other[..]
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &[B; N]) -> bool {
|
|
|
|
self[..] != other[..]
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<'a, 'b, A, B, const N: usize> PartialEq<[B]> for [A; N]
|
|
|
|
where
|
|
|
|
A: PartialEq<B>,
|
|
|
|
[A; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &[B]) -> bool {
|
|
|
|
self[..] == other[..]
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &[B]) -> bool {
|
|
|
|
self[..] != other[..]
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<'a, 'b, A, B, const N: usize> PartialEq<[A; N]> for [B]
|
|
|
|
where
|
|
|
|
B: PartialEq<A>,
|
|
|
|
[A; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &[A; N]) -> bool {
|
|
|
|
self[..] == other[..]
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &[A; N]) -> bool {
|
|
|
|
self[..] != other[..]
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<'a, 'b, A, B, const N: usize> PartialEq<&'b [B]> for [A; N]
|
|
|
|
where
|
|
|
|
A: PartialEq<B>,
|
|
|
|
[A; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &&'b [B]) -> bool {
|
|
|
|
self[..] == other[..]
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &&'b [B]) -> bool {
|
|
|
|
self[..] != other[..]
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<'a, 'b, A, B, const N: usize> PartialEq<[A; N]> for &'b [B]
|
|
|
|
where
|
|
|
|
B: PartialEq<A>,
|
|
|
|
[A; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &[A; N]) -> bool {
|
|
|
|
self[..] == other[..]
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &[A; N]) -> bool {
|
|
|
|
self[..] != other[..]
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<'a, 'b, A, B, const N: usize> PartialEq<&'b mut [B]> for [A; N]
|
|
|
|
where
|
|
|
|
A: PartialEq<B>,
|
|
|
|
[A; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &&'b mut [B]) -> bool {
|
|
|
|
self[..] == other[..]
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &&'b mut [B]) -> bool {
|
|
|
|
self[..] != other[..]
|
|
|
|
}
|
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<'a, 'b, A, B, const N: usize> PartialEq<[A; N]> for &'b mut [B]
|
|
|
|
where
|
|
|
|
B: PartialEq<A>,
|
|
|
|
[A; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &[A; N]) -> bool {
|
|
|
|
self[..] == other[..]
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &[A; N]) -> bool {
|
|
|
|
self[..] != other[..]
|
|
|
|
}
|
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
// NOTE: some less important impls are omitted to reduce code bloat
|
|
|
|
// __impl_slice_eq2! { [A; $N], &'b [B; $N] }
|
|
|
|
// __impl_slice_eq2! { [A; $N], &'b mut [B; $N] }
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<T: Eq, const N: usize> Eq for [T; N] where [T; N]: LengthAtMost32 {}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<T: PartialOrd, const N: usize> PartialOrd for [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn partial_cmp(&self, other: &[T; N]) -> Option<Ordering> {
|
|
|
|
PartialOrd::partial_cmp(&&self[..], &&other[..])
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
2019-07-25 18:06:26 +02:00
|
|
|
#[inline]
|
|
|
|
fn lt(&self, other: &[T; N]) -> bool {
|
|
|
|
PartialOrd::lt(&&self[..], &&other[..])
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn le(&self, other: &[T; N]) -> bool {
|
|
|
|
PartialOrd::le(&&self[..], &&other[..])
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ge(&self, other: &[T; N]) -> bool {
|
|
|
|
PartialOrd::ge(&&self[..], &&other[..])
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn gt(&self, other: &[T; N]) -> bool {
|
|
|
|
PartialOrd::gt(&&self[..], &&other[..])
|
|
|
|
}
|
|
|
|
}
|
2019-07-05 23:59:59 -07:00
|
|
|
|
2019-07-25 18:06:26 +02:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
|
|
|
impl<T: Ord, const N: usize> Ord for [T; N]
|
|
|
|
where
|
|
|
|
[T; N]: LengthAtMost32,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn cmp(&self, other: &[T; N]) -> Ordering {
|
|
|
|
Ord::cmp(&&self[..], &&other[..])
|
2019-07-05 23:59:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Implemented for lengths where trait impls are allowed on arrays in core/std
|
|
|
|
#[rustc_on_unimplemented(
|
|
|
|
message="arrays only have std trait implementations for lengths 0..=32",
|
|
|
|
)]
|
|
|
|
#[unstable(feature = "const_generic_impls_guard", issue = "0",
|
|
|
|
reason = "will never be stable, just a temporary step until const generics are stable")]
|
|
|
|
pub trait LengthAtMost32 {}
|
|
|
|
|
|
|
|
macro_rules! array_impls {
|
|
|
|
($($N:literal)+) => {
|
|
|
|
$(
|
|
|
|
#[unstable(feature = "const_generic_impls_guard", issue = "0")]
|
|
|
|
impl<T> LengthAtMost32 for [T; $N] {}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-31 05:41:25 -04:00
|
|
|
array_impls! {
|
|
|
|
0 1 2 3 4 5 6 7 8 9
|
|
|
|
10 11 12 13 14 15 16 17 18 19
|
|
|
|
20 21 22 23 24 25 26 27 28 29
|
|
|
|
30 31 32
|
|
|
|
}
|
2015-08-14 10:11:19 -07:00
|
|
|
|
|
|
|
// The Default impls cannot be generated using the array_impls! macro because
|
|
|
|
// they require array literals.
|
|
|
|
|
|
|
|
macro_rules! array_impl_default {
|
|
|
|
{$n:expr, $t:ident $($ts:ident)*} => {
|
|
|
|
#[stable(since = "1.4.0", feature = "array_default")]
|
|
|
|
impl<T> Default for [T; $n] where T: Default {
|
|
|
|
fn default() -> [T; $n] {
|
|
|
|
[$t::default(), $($ts::default()),*]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
array_impl_default!{($n - 1), $($ts)*}
|
|
|
|
};
|
|
|
|
{$n:expr,} => {
|
|
|
|
#[stable(since = "1.4.0", feature = "array_default")]
|
|
|
|
impl<T> Default for [T; $n] {
|
|
|
|
fn default() -> [T; $n] { [] }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
array_impl_default!{32, T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T}
|