Iterator::any
Iterator::any
是一个函数,它接受一个迭代器作为参数。如果任何元素满足给定的条件,则返回 true
,否则返回 false
。其签名如下:
pub trait Iterator {
// 被迭代的类型
type Item;
// `any` 接受 `&mut self`,意味着调用者可能被借用
// 和修改,但不会被消耗
fn any<F>(&mut self, f: F) -> bool where
// `FnMut` 表示任何捕获的变量最多只能被修改,不能被消耗
// `Self::Item` 表示它通过值将参数传递给闭包
F: FnMut(Self::Item) -> bool;
}