Logo

Programming-Idioms

History of Idiom 12 > diff from v94 to v95

Edit summary for version 95 by programming-idioms.org:
[Rust] Avoid link shortener if possible

Version 94

2020-03-20, 17:37:15

Version 95

2020-03-20, 18:01:02

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 member membership
Extra Keywords
array vector member membership
Code
(&list).into_iter().any(|v| v == &x)
Code
(&list).into_iter().any(|v| v == &x)
Comments bubble
This is the the truly general version, but it isn't the most idiomatic.
Comments bubble
This is the the truly general version, but it isn't the most idiomatic.
Doc URL
https://doc.rust-lang.org/std/iter/trait.IntoIterator.html#tymethod.into_iter
Doc URL
https://doc.rust-lang.org/std/iter/trait.IntoIterator.html#tymethod.into_iter
Demo URL
https://is.gd/hZWiKW
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=1f4f445c64974c240ac90d5aa8735716