Search⌘ K
AI Features

HashSets

Explore HashSets in Rust as unique-value collections that support operations such as union, difference, intersection, and symmetric difference. Learn how to create and manipulate HashSets while understanding constraints like stored data types and behavior with duplicates.

As we explained in the previous section, the hash part of HashSets just refers to a way of storing the data in the structure. We can ignore this as long as we do not need highly specialized, embedded code. For our purposes today, HashSets are simply sets.

HashSets are unique-value stores

HashSets only store unique values. A HashSet is a HashMap that only stores the keys, without values :

...