Quantcast
Channel: Idiomatic way to only get insides of `Some` from a vector of options? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by nikoss for Idiomatic way to only get insides of `Some` from a vector of options?

$
0
0

In your case since you are not doing any mapping, I would suggest using flattening instead of filter_maping.Which in my opinion is much clearer and more self explanatory.

    let optvec = vec![Some(1), None, Some(4), None];    let filtered: Vec<i32> = optvec.iter().flatten().cloned().collect();    assert_eq!(filtered, &[1, 4]);

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>