Open
Description
What it does
Lints implementations of core::iter::Iterator
that do not specialize the fold
method.
Advantage
- Methods that consume the entire iterator (
for_each
,count
, ...) rely onfold
by default and would benefit fromfold
being specialized. - Adaptor iterators might use
fold
(or related methods) for their own usage and would benefit as well.
Drawbacks
Specialize it may not be faster than the default behavior.
Example
struct Iter(u8);
impl Iterator for Iter {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
todo!()
}
}
Could be written as:
struct Iter(u8);
impl Iterator for Iter {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
todo!()
}
fn fold<B, F>(self, init: B, f: F) -> B
where
F: FnMut(B, Self::Item) -> B
{
todo!()
}
}