What is the idiomatic way to join two HashSet?

I have have a hashset, and I want to insert all the element of the other hashset into it. How should I do it?

hash1 = hash1.union(&hash2).collect();
for element in hash2 {

Or maybe there is a better way?

1 Like

One more option is

1 Like

I looked at the doc of HashSet but didn't noticed the Extend trait. I was really surprised to not find something like this.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.