HashSet and BTreeSet
Sets hold unique values. BTreeSet keeps them sorted.
Example
fn main() {
use std::collections::{BTreeSet, HashSet};
let h: HashSet<i32> = [1, 2, 2, 3].into_iter().collect();
let b: BTreeSet<i32> = [3, 1, 2].into_iter().collect();
println!("{} {:?}", h.len(), b);
}Result
3 {1, 2, 3}Exercise
Sorted set.
SetQuiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.