Is there a built-in authentication feature in Rust?

I have a vector Optionand I want to filter only Somes. I use filter_mapwith id:

let v = vec![Some(1), None, Some(2)];
for i in v.into_iter().filter_map(|o| o) {
    println!("{}", i);
}

Is there a built-in function that allows you to write something like filter_map(identity)?

+9
source share
2 answers

No, in stable Rust there is no such function. You can create your own:

fn id<T>(v: T) -> T { v } 

Although most people just embed code, so do you.

+8
source

Now there is a night function . std::convert::identity

+3
source

All Articles