pub trait ArrayMap<U>: Array {
type Map: Array<Item = U>;
// Provided method
fn map<F>(self, f: F) -> Self::Map
where F: FnMut(Self::Item) -> U { ... }
}Expand description
Represent array which elements can be mapped (actually any array)
Required Associated Types§
Provided Methods§
Sourcefn map<F>(self, f: F) -> Self::Map
fn map<F>(self, f: F) -> Self::Map
Maps elements of the array
§Examples
use arraylib::ArrayMap;
let arr = [1, 2, 3, 4, 5];
let res = arr.map(|x| 2i32.pow(x));
assert_eq!(res, [2, 4, 8, 16, 32])NOTE: it’s nighly recommended to use iterators when you need to
perform more that one operation (e.g. map + as_ref) because iterators
are lazy and ArrayMap isn’t.
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.