Skip to main content

IterExtras

Trait IterExtras 

Source
pub trait IterExtras: Iterator + Sized {
    // Provided methods
    fn for_each_with<T, F>(self, t: T, f: F)
       where T: Clone,
             F: FnMut(Self::Item, T) { ... }
    fn for_each_try_with<T, F>(self, t: T, f: F) -> Result<(), SerError>
       where T: TryClone,
             F: FnMut(Self::Item, T) { ... }
}
Expand description

Additional iterator functions

Provided Methods§

Source

fn for_each_with<T, F>(self, t: T, f: F)
where T: Clone, F: FnMut(Self::Item, T),

Iterate over each item in the iterator and apply a function to it and a clone of the given value t

Behaves like iterator.for_each(|item| f(item, t.clone())), except that it avoids cloning in the case where the iterator contains a single item or for the last item in a larger iterator.

Use this when cloning T is relatively expensive compared to f.

Source

fn for_each_try_with<T, F>(self, t: T, f: F) -> Result<(), SerError>
where T: TryClone, F: FnMut(Self::Item, T),

Iterate over each item in the iterator and apply a function to it and a clone of the given value t if such a clone can be created

Behaves like iterator.for_each(|item| f(item, t.try_clone())), except that it avoids cloning in the case where the iterator contains a single item or for the last item in a larger iterator. It also shortcircuits on cloning errors.

Use this when trying to clone T is relatively expensive compared to f.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> IterExtras for T
where T: Iterator + Sized,