Use std::collections::HashSet to store unique items and check for their existence efficiently.
Use std::collections::HashSet to store unique values with O(1) average lookup time. Import the type, create a new set, insert items, and check for existence using insert and contains.
use std::collections::HashSet;
let mut refs = HashSet::new();
refs.insert("link_ref".to_string());
if refs.contains("link_ref") {
println!("Found");
}
A HashSet is like a digital list that automatically prevents duplicate entries. It is ideal when you need to quickly check if an item exists or ensure a collection contains only unique values, similar to a guest list where you only care if someone is on it, not their order.