Trait SliceArrayExt

Source
pub trait SliceArrayExt<T> {
    // Required methods
    fn as_array<V: IsSliceomorphic<Element = T>>(&self) -> &V;
    fn as_mut_array<V: IsSliceomorphic<Element = T>>(&mut self) -> &mut V;

    // Provided method
    fn to_array<V>(&self) -> V
       where V: Clone + IsSliceomorphic<Element = T> { ... }
}
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]>().

§Panics

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

§Implementors

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].

§Notice

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§

Source

fn as_array<V: IsSliceomorphic<Element = T>>(&self) -> &V

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

Source

fn as_mut_array<V: IsSliceomorphic<Element = T>>(&mut self) -> &mut V

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

Provided Methods§

Source

fn to_array<V>(&self) -> V
where V: Clone + IsSliceomorphic<Element = T>,

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

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

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<T> SliceArrayExt<T> for [T]

Source§

fn as_array<V: IsSliceomorphic<Element = T>>(&self) -> &V

Source§

fn as_mut_array<V: IsSliceomorphic<Element = T>>(&mut self) -> &mut V

Implementors§