Trait Array

Source
pub trait Array:
    Array
    + ArrayPrereq<Item = <Self as AsSlice>::Item>
    + AsArray
    + IntoArray { }
Expand description

A trait for any array, with item 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>::Item>
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.

Implementations on Foreign Types§

Source§

impl<Item, const LENGTH: usize> Array for [Item; LENGTH]

Implementors§