From the course: Rust for Data Engineering

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Storing unique fruits using HashSet in Rust

Storing unique fruits using HashSet in Rust - Rust Tutorial

From the course: Rust for Data Engineering

Storing unique fruits using HashSet in Rust

- [Instructor] All right, in this video, I have a simple Rust program that generates a list of 100 random fruits and calculates the number of unique fruits we end up with. So let's go ahead and take a look at the very beginning here. One of the key takeaways, as well as I'm using the rand external crate here to help me out. And in particular, the sequence slice, random and thread, rng here, are doing a lot of the heavy lifting, because they'll generate a random choice from a list of fruits. And a lot of times, this is a great way to generate random choices, is in this case, this is a vector. And I'm going to feed it into the random selections from the rand crate. Now, we're going to use a hash set from the standard library collection as well. So that's another thing to pay attention to. And one of the key properties of a hash set is that it will only store unique elements. So this is perfect for this kind of use…

Contents