I have a vec i64 that store some element with some entity ids. I want to filter some specify entity id and return a new vec. what I am trying to implement this operation like this way in rust(this is a minimal example, the real element was some word Object):
fn main() {
let current_word_id:i64 =1;
let wordIds:Vec<i64> = Vec::new();;
let current_sentences: Vec<i64> = wordIds
.iter()
.filter(|sen| sen == current_word_id)
.collect();
}
when I compile this code,facing a problem like this:
error[E0277]: can't compare `&&i64` with `i64`
--> src/main.rs:16:27
|
16 | .filter(|sen| sen == current_word_id)
| ^^ no implementation for `&&i64 == i64`
|
= help: the trait `PartialEq<i64>` is not implemented for `&&i64`
error[E0277]: a value of type `Vec<i64>` cannot be built from an iterator over elements of type `&i64`
--> src/main.rs:17:10
|
17 | .collect();
| ^^^^^^^ value of type `Vec<i64>` cannot be built from `std::iter::Iterator<Item=&i64>`
|
= help: the trait `FromIterator<&i64>` is not implemented for `Vec<i64>`
Some errors have detailed explanations: E0277, E0432.
For more information about an error, try `rustc --explain E0277`.
I am follow the https://codereview.stackexchange.com/questions/244880/filtering-a-vec-of-structs-and-creating-new-vector-of-strings-or-strs-in-rust. why did not work as expect? What should I do to make it work? what is the right way to do some filter with vec in rust?