I'm using the Uuid crate to give unique ids to instantiate each new version of a Node
struct with a unique identifier. Sometimes I'd like to filter these structs using .contains()
to check if a struct's id
is inside some array of Vec<Uuid>
.
use uuid::Uuid;
struct Node {
id: Uuid,
}
impl Node {
fn new() -> Self {
let new_obj = Node {
id: Uuid::new_v4()
};
new_obj
}
fn id(&self) -> Uuid {
self.id
}
}
fn main() {
let my_objs = vec![
Node::new(),
Node::new(),
Node::new(),
Node::new(),
];
let some_ids = vec![my_objs[0].id(), my_objs[3].id()];
}
fn filter_objs(all_items: &Vec<Node>, to_get: &Vec<Uuid>){
for z in to_get {
let wanted_objs = &all_items.iter().filter(|s| to_get.contains(*s.id()) == true);
}
}
However this gives the error:
error[E0614]: type `Uuid` cannot be dereferenced
--> src/main.rs:32:72
|
32 | let wanted_objs = &all_items.iter().filter(|s| to_get.contains(*s.id()) == true);
| ^^^^^^^
How can I enable dereferencing for the Uuid
type to solve this problem?
Playground
question from:
https://stackoverflow.com/questions/65877812/how-to-dereference-uuid-type 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…