Rust 中是否有内置标识函数?

问题描述:

我有一个 Option 向量,我只想过滤 Some .我使用带有身份的 filter_map:

I have a vector of Options and I want to filter only the Somes. 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)?

有一个 std::convert::identity 函数自 Rust 1.33.0.