Guest User

Untitled

a guest
Oct 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. use std::collections::HashSet;
  2.  
  3. fn main() {
  4. let mut s1 = HashSet::new();
  5. s1.insert(String::from("a"));
  6. s1.insert(String::from("b"));
  7. s1.insert(String::from("c"));
  8. let mut s2 = HashSet::new();
  9. s2.insert(String::from("d"));
  10. s2.insert(String::from("b"));
  11. s2.insert(String::from("c"));
  12. assert!(s2.contains("d"));
  13. let mut union = s1.union(&s2);
  14. // Compile error
  15. assert!(union.collect::<HashSet<_>>().contains("d"));
  16. // Alternative assertions
  17. assert!(union.position(|i| i == "d").is_some());
  18. }
Add Comment
Please, Sign In to add comment