SliceExt

Trait SliceExt 

Source
pub trait SliceExt: Sealed {
    type Elem;

    // Required method
    fn generate_boxed<F: FnMut(usize) -> Self::Elem>(
        n: usize,
        f: F,
    ) -> Box<Self>;
}
Expand description

Extension trait for dynamically sized slices.

Allows you to initialize a boxed slice like this:

use init_array::SliceExt;

let arr: Box<[usize]> = <[usize]>::generate_boxed(5, |i| i * i);
assert_eq!(&*arr, &[0, 1, 4, 9, 16]);

Required Associated Types§

Required Methods§

Source

fn generate_boxed<F: FnMut(usize) -> Self::Elem>(n: usize, f: F) -> Box<Self>

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

Source§

type Elem = T

Source§

fn generate_boxed<F: FnMut(usize) -> Self::Elem>(n: usize, f: F) -> Box<Self>

Implementors§