IterScanB

Trait IterScanB 

Source
pub trait IterScanB: Iterator + Sized {
    // Provided method
    fn scanb<S, B, F>(self, init_state: S, f: F) -> ScanB<Self, S, F> 
       where F: FnMut(&mut S, Self::Item) -> B { ... }
}
Expand description

Like the Iterator::scan, but use B, instead of Option<B>, which can bring better size_hint and ergonomics.

At the same time, it will also be able to implement ExactSizeIterator and FusedIterator

Provided Methods§

Source

fn scanb<S, B, F>(self, init_state: S, f: F) -> ScanB<Self, S, F>
where F: FnMut(&mut S, Self::Item) -> B,

An iterator adapter which, like Iterator::scan, but returns a value of B instead of Option<B>. which can bring better size_hint and ergonomics.

At the same time, it will also be able to implement ExactSizeIterator and FusedIterator

§Examples
let a = [1, 2, 3, 4];

let mut iter = a.iter().scanb(1, |state, &x| {
    *state *= x;
    -*state
});

assert_eq!(iter.next(), Some(-1));
assert_eq!(iter.next(), Some(-2));
assert_eq!(iter.next(), Some(-6));
assert_eq!(iter.next(), Some(-24));
assert_eq!(iter.next(), None);

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§