Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. use std::borrow::Borrow;
  2.  
  3. pub trait IntoIterExt: IntoIterator {
  4. fn contains_any_of<U>(self, other: U) -> bool where Self::Item: PartialEq,
  5. U: IntoIterator,
  6. U::Item: Borrow<Self::Item>;
  7. }
  8.  
  9. impl<T: IntoIterator> IntoIterExt for T {
  10. fn contains_any_of<U>(self, _other: U) -> bool where Self::Item: PartialEq,
  11. U: IntoIterator,
  12. U::Item: Borrow<Self::Item> {
  13. true
  14. }
  15. }
  16.  
  17. #[test]
  18. fn contains_empty_coll_contains_empty_vec_yields_true() {
  19. // given an empty collection
  20. let coll = Vec::<i32>::new();
  21.  
  22. // when `contains()` invoked with `Vec` empty set
  23. let result = coll.contains_any_of(Vec::<i32>::new());
  24.  
  25. // then the result should be true
  26. assert_eq!(true, result);
  27. }
  28.  
  29. #[test]
  30. fn contains_empty_coll_contains_empty_slice_yields_true() {
  31. // given an empty collection
  32. let coll = Vec::<i32>::new();
  33.  
  34. // when `contains()` invoked with `slice` empty set
  35. let result = coll.contains_any_of(&[]);
  36.  
  37. // then the result should be true
  38. assert_eq!(true, result);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement