Trait ArrayIter

Source
pub trait ArrayIter<T: ArrayElement>
where Self: Sized + Clone,
{ // Required methods fn for_each<F: FnMut(&T)>(&self, f: F) -> Result<(), ArrayError>; fn for_each_e<F: FnMut(usize, &T)>(&self, f: F) -> Result<(), ArrayError>; fn filter<F: FnMut(&T) -> bool>(&self, f: F) -> Result<Array<T>, ArrayError>; fn filter_e<F: FnMut(usize, &T) -> bool>( &self, f: F, ) -> Result<Array<T>, ArrayError>; }
Expand description

ArrayTrait - Array Iterable functions

Required Methods§

Source

fn for_each<F: FnMut(&T)>(&self, f: F) -> Result<(), ArrayError>

Loop over array elements

§Arguments
  • f - function to be called on each array element
§Examples
use arr_rs::prelude::*;

let arr = Array::new(vec![1, 2, 3, 4, 5, 6, 7, 8], vec![2, 4]).unwrap();
arr.for_each(|item| println!("{item}")).unwrap();
§Errors

may returns ArrayError

Source

fn for_each_e<F: FnMut(usize, &T)>(&self, f: F) -> Result<(), ArrayError>

Loop over enumerated array elements

§Arguments
  • f - function to be called on each array element
§Examples
use arr_rs::prelude::*;

let arr = Array::new(vec![1, 2, 3, 4, 5, 6, 7, 8], vec![2, 4]).unwrap();
arr.for_each_e(|idx, item| println!("{idx}:{item}")).unwrap();
§Errors

may returns ArrayError

Source

fn filter<F: FnMut(&T) -> bool>(&self, f: F) -> Result<Array<T>, ArrayError>

Filter over array elements Returns a flat filtered array

§Arguments
  • f - function to be called on each array element
§Examples
use arr_rs::prelude::*;

let arr: Array<i32> = Array::new(vec![1, 2, 3, 4, 5, 6, 7, 8], vec![2, 4]).unwrap();
arr.filter(|item| item % 2 == 0).unwrap();
§Errors

may returns ArrayError

Source

fn filter_e<F: FnMut(usize, &T) -> bool>( &self, f: F, ) -> Result<Array<T>, ArrayError>

Filter over enumerated array elements Returns a flat filtered array

§Arguments
  • f - function to be called on each array element
§Examples
use arr_rs::prelude::*;

let arr: Array<i32> = Array::new(vec![1, 2, 3, 4, 5, 6, 7, 8], vec![2, 4]).unwrap();
arr.filter_e(|idx, item| item % (idx + 1) as i32 == 0).unwrap();
§Errors

may returns ArrayError

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.

Implementors§