Logo

Programming-Idioms

History of Idiom 52 > diff from v48 to v49

Edit summary for version 49 by programming-idioms.org:
[Rust] +DemoURL

Version 48

2020-12-14, 22:37:19

Version 49

2020-12-14, 23:08:09

Idiom #52 Check if map contains value

Determine whether map m contains an entry with value v, for some key.

Idiom #52 Check if map contains value

Determine whether map m contains an entry with value v, for some key.

Variables
m,v
Variables
m,v
Extra Keywords
table dictionary hash
Extra Keywords
table dictionary hash
Imports
use std::collections::BTreeMap;
Imports
use std::collections::BTreeMap;
Code
let does_contain = m.values()
        .any(|&val| *val == v);
Code
let does_contain = m.values().any(|&val| *val == v);
Comments bubble
Works the same for HashMap.
Comments bubble
Works the same for HashMap.
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=e51781a1c9400c7e17423a3d06c64b27