Logo

Programming-Idioms

History of Idiom 12 > diff from v52 to v53

Edit summary for version 53 by bugaevc:
[Rust] Moved the comment into the "explain" section and added links

Version 52

2017-04-19, 04:57:30

Version 53

2017-05-19, 21:48:13

Idiom #12 Check if list contains a value

Check if list contains a value x.
list is an iterable finite container.

Illustration

Idiom #12 Check if list contains a value

Check if list contains a value x.
list is an iterable finite container.

Illustration
Extra Keywords
array vector
Extra Keywords
array vector
Code
list.contains(&x); // Or, for most iterable types, `list.iter().any(|v| v == &x)`
Code
list.contains(&x);
Comments bubble
Technically, the truly general version is `(&list).into_iter().any(|v| v == &x)` but this isn't idiomatic.
Comments bubble
Or, for most iterable types, `list.iter().any(|v| v == &x)`

Technically, the truly general version is `(&list).into_iter().any(|v| v == &x)` but this isn't idiomatic.
Doc URL
https://doc.rust-lang.org/std/primitive.slice.html#method.contains
Demo URL
https://is.gd/iugb8l