Struct ::std::collections::HashSet
Methods
Creates an empty HashSet
.
The hash set is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
Examples
use HashSet;
let set = new;
Creates an empty HashSet
with at least the specified capacity.
The hash set will be able to hold at least capacity
elements without reallocating. This method is allowed to allocate for more elements than capacity
. If capacity
is 0, the hash set will not allocate.
Examples
use HashSet;
let set = with_capacity;
assert!;
Returns the number of elements in the set.
Examples
use HashSet;
let v = new;
assert_eq!;
v.insert;
assert_eq!;
Returns true
if the set contains no elements.
Examples
use HashSet;
let v = new;
assert!;
v.insert;
assert!;
Returns the number of elements the set can hold without reallocating.
Examples
use HashSet;
let set = with_capacity;
assert!;
Adds a value to the set.
Returns whether the value was newly inserted. That is:
- If the set did not previously contain this value,
true
is returned. - If the set already contained this value,
false
is returned.
Examples
use HashSet;
let set = new;
assert_eq!;
assert_eq!;
assert_eq!;
Removes a value from the set. Returns whether the value was present in the set.
Examples
use HashSet;
let set = new;
set.insert;
assert_eq!;
assert_eq!;
Returns true
if the set contains a value.
Examples
use HashSet;
let set = from;
assert_eq!;
assert_eq!;
Clears the set, removing all values.
Examples
use HashSet;
let v = new;
v.insert;
v.clear;
assert!;
Visits the values representing the difference, i.e., the values that are in self
but not in other
.
Examples
use HashSet;
let a = from;
let b = from;
let diff = a.difference .;
assert_eq!;
// Note that difference is not symmetric,
// and `b - a` means something else:
let diff = b.difference .;
assert_eq!;
Visits the values representing the intersection, i.e., the values that are both in self
and other
.
When an equal element is present in self
and other
then the resulting Intersection
may yield values to one or the other.
Examples
use HashSet;
let a = from;
let b = from;
let values = a.intersection .;
assert_eq!;
Visits the values representing the union, i.e., all the values in self
or other
, without duplicates.
Examples
use HashSet;
let a = from;
let b = from;
let union = a.union .;
assert_eq!;
let union = b.union .;
assert_eq!;
Iterate over the hash set.
Examples
use HashSet;
let set = from;
let vec = set.iter .;
vec.sort;
assert_eq!;
Protocols
for item in value
Convert the set into an iterator.
Examples
use HashSet;
let set = from;
let vec = ;
for value in set
vec.sort;
assert_eq!;
println
Write a debug representation to a string.
This calls the [STRING_DEBUG
] protocol over all elements of the collection.
Examples
use HashSet;
let set = from;
println!;
if value == b
Perform a partial equality test between two sets.
Examples
Examples
use HashSet;
let set = from;
assert_eq!;
assert_ne!;
if value == b
Perform a total equality test between two sets.
Examples
use eq;
use HashSet;
let set = from;
assert!;
assert!;