In Rust, you can check if two sets are equal by comparing them using the '==' operator.
In this example,
set1
and set2
, containing elements of the sets.fn main() {
let set1: std::collections::HashSet<_> = [1, 2, 3, 4].iter().cloned().collect();
let set2: std::collections::HashSet<_> = [1, 2, 3, 4].iter().cloned().collect();
let are_equal = set1 == set2;
println!("{:?}", are_equal);
}
true
In this example,
set1
and set2
, containing elements of the sets.fn main() {
let set1: std::collections::HashSet<_> = [1, 2, 3, 4].iter().cloned().collect();
let set2: std::collections::HashSet<_> = [4, 3, 2, 1].iter().cloned().collect();
let are_equal = set1 == set2;
println!("{:?}", are_equal);
}
false
In this tutorial, we learned How to check if Two Sets are Equal in Rust language with well detailed examples.