Iterator::any
Iterator::any
是一个函数,若传给它一个迭代器(iterator),当其中任一元素满足谓词(predicate)时它将返回 true
,否则返回 false
(译注:谓词是闭包规定的, true
/false
是闭包作用在元素上的返回值)。它的签名如下:
pub trait Iterator {
// 被迭代的类型。
type Item;
// `any` 接受 `&mut self` 参数(译注:回想一下,这是 `self: &mut Self` 的简写)
// 表明函数的调用者可以被借用和修改,但不会被消耗。
fn any<F>(&mut self, f: F) -> bool where
// `FnMut` 表示被捕获的变量最多只能被修改,而不能被消耗。
// `Self::Item` 表明变量是通过值传递给闭包(译注:是迭代器对应的元素的类型)
F: FnMut(Self::Item) -> bool {}
}