Trait SliceNestExt

Source
pub trait SliceNestExt<T> {
    // Required methods
    fn nest<V: IsSliceomorphic<Element = T>>(&self) -> &[V];
    fn nest_mut<V: IsSliceomorphic<Element = T>>(&mut self) -> &mut [V];
}
Expand description

Permits viewing a slice as a slice of arrays.

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

§Panics

All methods panic if the input length is not divisible by n.

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

The implementation for N=0 panics! (even if the length of the slice is zero, as in this case the length of the nested slice would be degenerate)

§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 nest<V: IsSliceomorphic<Element = T>>(&self) -> &[V]

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

Source

fn nest_mut<V: IsSliceomorphic<Element = T>>(&mut self) -> &mut [V]

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

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

Source§

fn nest<V: IsSliceomorphic<Element = T>>(&self) -> &[V]

Source§

fn nest_mut<V: IsSliceomorphic<Element = T>>(&mut self) -> &mut [V]

Implementors§