Skip to main content

PureIterExt

Trait PureIterExt 

Source
pub trait PureIterExt: Iterator + Sized {
    // Provided method
    fn pure_map<F, U>(self, f: F) -> PureMap<Self, F> 
       where F: Fn(Self::Item) -> U { ... }
}
Expand description

Similar to an Iterator, but assuming the input function has no side effects, it can avoid additional calls

Provided Methods§

Source

fn pure_map<F, U>(self, f: F) -> PureMap<Self, F>
where F: Fn(Self::Item) -> U,

§Examples
use pure_iter::PureIterExt;

let mut a = AtomicU32::new(0);
let mut b = AtomicU32::new(0);

let c = (0..3).map(|_| a.fetch_add(1, Release)).nth(2);
let d = (0..3).pure_map(|_| b.fetch_add(1, Release)).nth(2);

assert_eq!(c, Some(2));
assert_eq!(d, Some(0));

assert_eq!(a.load(Acquire), 3);
assert_eq!(b.load(Acquire), 1);

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§