pub trait IterCloneExt: Iterator + Clone {
// Provided methods
fn split<P>(self, pred: P) -> Split<Self, P> ⓘ
where P: FnMut(&Self::Item) -> bool + Clone { ... }
fn split_inclusive<P>(self, pred: P) -> SplitInclusive<Self, P> ⓘ
where P: FnMut(&Self::Item) -> bool + Clone { ... }
}
Expand description
An extension trait for Iterator + Clone
Provided Methods§
Sourcefn split<P>(self, pred: P) -> Split<Self, P> ⓘ
fn split<P>(self, pred: P) -> Split<Self, P> ⓘ
Splits an iterator into an iterator of iterators.
§Example
let nums = [0u32, 10, 20, 0, 0, 5, 50, 0];
let split_nums: Vec<Vec<u32>> = nums
.iter()
.filter(|n| *n % 2 == 0)
.split(|n| **n == 0)
.map(|n| n.copied().collect::<Vec<u32>>())
.collect();
let expected: &[&[u32]] = &[&[], &[10, 20], &[], &[50], &[]];
assert_eq!(split_nums, expected);
Sourcefn split_inclusive<P>(self, pred: P) -> SplitInclusive<Self, P> ⓘ
fn split_inclusive<P>(self, pred: P) -> SplitInclusive<Self, P> ⓘ
Splits an iterator into an iterator of iterators. Includes the separator at the end.
§Example
let nums = [0u32, 10, 20, 0, 0, 5, 50, 0];
let split_nums: Vec<Vec<u32>> = nums
.iter()
.filter(|n| *n % 2 == 0)
.split_inclusive(|n| **n == 0)
.map(|n| n.copied().collect::<Vec<u32>>())
.collect();
let expected: &[&[u32]] = &[&[0], &[10, 20, 0], &[0], &[50, 0], &[]];
assert_eq!(split_nums, expected);
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.