Function array_tools::init_with_slice[][src]

pub fn init_with_slice<T, A>(slice: &[T]) -> Option<A> where
    A: FixedSizeArray<T>,
    T: Clone

Attempts to initialize array of T with slice of T ([T]).

  • If slice length is less than array length, this function returns None.
  • If slice length is greater or equal to array length, this function returns Some(array).

This function clones slice elements.

Examples

Not enough elements case.

use array_tools as art;

let slice = &[1i32, 2, 3, 4, 5, 6];
let result: Option<[i32; 8]> = art::init_with_slice(slice);

assert_eq!(result, None);



let slice = &[1i32, 2, 3, 4, 5, 6];
let result: Option<[i32; 4]> = art::init_with_slice(slice);

assert_eq!(result, Some([1i32, 2, 3, 4]));