Guest User

Untitled

a guest
Feb 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. struct ContainerFoo(i32, i32);
  2.  
  3. struct ContainerBar(i64, i64);
  4.  
  5. trait Contains {
  6. type A;
  7. type B;
  8.  
  9. fn contains(&self, &Self::A, &Self::B) -> bool;
  10. }
  11.  
  12. impl Contains for ContainerFoo {
  13. type A = i32;
  14. type B = i32;
  15.  
  16. fn contains(&self, number_1: &i32, number_2: &i32) -> bool {
  17. (&self.0 == number_1) && (&self.1 == number_2)
  18. }
  19. }
  20.  
  21. impl Contains for ContainerBar {
  22. type A = i64;
  23. type B = i64;
  24.  
  25. fn contains(&self, number_1: &i64, number_2: &i64) -> bool {
  26. (&self.0 == number_1) && (&self.1 == number_2)
  27. }
  28. }
  29.  
  30. struct FooBar<'a, Ta: 'a, Tb: 'a> {
  31. pub container: &'a Contains<A=Ta, B=Tb>,
  32. }
  33.  
  34. fn main() {
  35. let number_1 = 3;
  36. let number_2 = 10;
  37.  
  38. let foobar = FooBar {
  39. container: &ContainerFoo(number_1, number_2),
  40. };
  41.  
  42. println!("Does container contain {} and {}: {}",
  43. &number_1, &number_2,
  44. foobar.container.contains(&number_1, &number_2));
  45. }
Add Comment
Please, Sign In to add comment