pub trait Mapper { fn mapper P>(&self, f: F) -> Vec

; fn iterate(&self, f: F); fn mutate T>(&mut self, f: F) -> &Vec; } impl Mapper for Vec { fn mapper P>(&self, f: F) -> Vec

{ return self.into_iter().map(f).collect::>(); } fn iterate(&self, f: F) { for x in self.iter() { f(x); } } fn mutate T>(&mut self, f: F) -> &Vec { for x in self.iter_mut() { *x = f(x); } return self; } } #[cfg(test)] mod tests { use crate::vector::mapper_trait::Mapper; #[test] fn test_mapper_trait() { let arr = vec![1, 2, 3]; println!("original: vec = {:?}", arr); let vec = arr.mapper(|x| x + 1); println!("original: arr = {:?}", arr); println!("mapped: vec = {:?}", vec); } }