2015-11-04 65 views

回答

6

它需要能够改变self,因为它正在推进迭代器。每次调用next时间,迭代器突变:

fn next(&mut self) -> Option<Self::Item>; 

这里是the implementation of find

fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item> where 
    Self: Sized, 
    P: FnMut(&Self::Item) -> bool, 
{ 
    for x in self.by_ref() { 
     if predicate(&x) { return Some(x) } 
    } 
    None 
} 
+0

感谢。非常明显! –

相关问题