2015-11-04 5 views

risposta

6

Deve essere in grado di mutare self perché sta avanzando l'iteratore. Ogni volta che si chiama next, l'iteratore è mutato:

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

Ecco 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

Grazie. Così ovvio! –