Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Call HashSet from library
- use std::collections::HashSet;
- fn main() {
- // Create an empty set
- let mut set = HashSet::new();
- // Insert item into the set
- set.insert("C++");
- set.insert("Java");
- set.insert("Python");
- set.insert("Rust");
- set.insert("Go");
- // Check the property of the set
- assert_eq!(set.len(), 5);
- assert_eq!(set.contains("Rust"), true);
- assert_eq!(set.contains("Lisp"), false);
- // Remove item from the set
- set.remove("Python");
- // Check the property of the set
- assert_eq!(set.len(), 4);
- assert_eq!(set.contains("Rust"), true);
- assert_eq!(set.contains("Python"), false);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement