from the src of core library, there is this function, but its definition is nowhere to be found. any idea?
iterator.rs
fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item> where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
{
self.try_for_each(move |x| {
if predicate(&x) { LoopState::Break(x) }
else { LoopState::Continue(()) }
}).break_value()
}
Ah! thanks! that's when google is not very helping in this case!
FWIW, IntelliJ also works awesome for these kind of searches:
Note that that code is equivalent to just
fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item> where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
{
self.try_for_each(move |x| {
if predicate(&x) { Err(x) }
else { Ok(()) }
}).err()
}
I just got myself super confused in the more complicated cases using Err
in the successful path, so ended up adding the extra isomorphic-to-Result enum to try to clarify the intent of the code.