pub trait IterExtras: Sized + Iterator {
// 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§
Sourcefn for_each_with<T, F>(self, t: T, f: F)
fn for_each_with<T, F>(self, t: T, f: F)
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.
Sourcefn for_each_try_with<T, F>(self, t: T, f: F) -> Result<(), SerError>
fn for_each_try_with<T, F>(self, t: T, f: F) -> Result<(), SerError>
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", so this trait is not object safe.