pub trait Array:
Array
+ AsArray
+ IntoArray
+ Pointee<Metadata = ()>
+ IntoIterator<Item = <Self as AsSlice>::Elem>
+ AsRef<[<Self as AsSlice>::Elem]>
+ AsMut<[<Self as AsSlice>::Elem]>
+ Borrow<[<Self as AsSlice>::Elem]>
+ BorrowMut<[<Self as AsSlice>::Elem]>
+ IndexMut<usize, Output = <[<Self as AsSlice>::Elem] as Index<usize>>::Output>
+ IndexMut<Range<usize>, Output = <[<Self as AsSlice>::Elem] as Index<Range<usize>>>::Output>
+ IndexMut<RangeInclusive<usize>, Output = <[<Self as AsSlice>::Elem] as Index<RangeInclusive<usize>>>::Output>
+ IndexMut<RangeFrom<usize>, Output = <[<Self as AsSlice>::Elem] as Index<RangeFrom<usize>>>::Output>
+ IndexMut<RangeTo<usize>, Output = <[<Self as AsSlice>::Elem] as Index<RangeTo<usize>>>::Output>
+ IndexMut<RangeToInclusive<usize>, Output = <[<Self as AsSlice>::Elem] as Index<RangeToInclusive<usize>>>::Output>
+ IndexMut<RangeFull, Output = <[<Self as AsSlice>::Elem] as Index<RangeFull>>::Output> { }Expand description
A trait for any array, with elem as an associated type, and length as an assiciated constant.
§Example
#![feature(const_trait_impl)]
#![feature(generic_const_exprs)]
use array_trait::*;
type Arr3 = [i8; 3];
const A: Arr3 = [1, 2, 3];
/// The trait can be used in a function like this:
const fn first<'a, T: ~const Array>(array: &'a T) -> Option<&'a <T as AsSlice>::Elem>
where
[(); T::LENGTH]: // This is required for now.
{
array.as_array().first()
}
assert_eq!(first(&A), Some(&1));
// The assiciated constant `LENGTH` equals the length of the array
assert_eq!(Arr3::LENGTH, 3);
assert_eq!(Arr3::LENGTH, A.len());Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.