pub trait SliceArrayExt<T> {
    fn as_array<V: IsSliceomorphic<Element = T>>(&self) -> &V;
fn as_mut_array<V: IsSliceomorphic<Element = T>>(&mut self) -> &mut V; fn to_array<V: IsSliceomorphic<Element = T>>(&self) -> V
        V: Clone
, { ... } }
Expand description

Permits viewing a slice as an array.

The output array length can often be inferred. When it is not, a turbofish can be used: .as_array::<[_; 3]>().


All methods panic if the slice is not exactly the requested length.


The methods are available on &[T] and &mut [T] for all T. Of course, they are also available on Vec<T> and any other type that derefs or unsizes to [T].


The existence of this trait is an implementation detail. Future versions may split it up, merge or rename it. Therefore, please do NOT use this trait as a generic bound in your code.

(Prefer V where V: IsSliceomorphic<Element=T> instead)

Required methods

View &[T] as &[T; n].

View &mut [T] as &mut [T; n].

Provided methods

Clone &[T] to [T; n].

This is provided because .as_array().clone() tends to cause trouble for type inference.

Implementations on Foreign Types