我有这个警告,但我不知道如何修复这个警告.
warning: method `next` can be confused for the standard trait method `std::iter::Iterator::next`
--> src/util/mod.rs:51:5
|
51 | / pub fn next(&mut self) -> Option<I::Item> {
52 | | if self.iterator.peek().is_some() {
53 | | self.prev = replace(&mut self.current, self.iterator.next());
54 | | return self.current.clone();
... |
59 | | None
60 | | }
| |_____^
|
= help: consider implementing the trait `std::iter::Iterator` or choosing a less ambiguous method name
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait
= note: `#[warn(clippy::should_implement_trait)]` on by default
这是我现在拥有的代码--一个能够窥视前一项的迭代器.next
方法也在代码片段中.
pub struct PrevPeekable<I>
where
I: Iterator,
<I as Iterator>::Item: Clone,
{
/// Iterator that `PrevPeekable` wraps
iterator: Peekable<I>,
/// The item before the current item
prev: Option<I::Item>,
/// The current item
current: Option<I::Item>,
/// Keeps track of whether the iterator has reached the end or not
finished: bool,
}
impl<I> PrevPeekable<I>
where
I: Iterator,
<I as Iterator>::Item: Clone,
{
/// Returns the next item in the iterator
pub fn next(&mut self) -> Option<I::Item> {
if self.iterator.peek().is_some() {
self.prev = replace(&mut self.current, self.iterator.next());
return self.current.clone();
} else if !self.finished {
self.prev = replace(&mut self.current, self.iterator.next());
self.finished = true;
}
None
}
}
先谢谢你.