Rust 中是否有内置标识函数?
问题描述:
我有一个 Option
向量,我只想过滤 Some
.我使用带有身份的 filter_map
:
I have a vector of Option
s and I want to filter only the Some
s. I use filter_map
with identity:
let v = vec![Some(1), None, Some(2)];
for i in v.into_iter().filter_map(|o| o) {
println!("{}", i);
}
是否有内置函数允许编写诸如 filter_map(identity)
之类的东西?
Is there a builtin function permitting to write something like filter_map(identity)
?