How to judge if a value is in the vec?

For example:

let a : i32 = 1;
let v :i32 = vec![1,2,3];

How to know if a in v or not?

v.contains(&a)

Sorry, but no method named contians for vec?

It’s in slice: https://doc.rust-lang.org/std/primitive.slice.html#method.contains

A Vec automatically coerces to a slice when needed.

2 Likes