Guest User

Untitled

a guest
Apr 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. extern crate itertools;
  2. use itertools::Itertools;
  3. #[derive(Debug)]
  4. struct Foo
  5. {
  6. slot_no: i32,
  7. have_a : i32,
  8. have_b: i32,
  9. value : i32
  10. }
  11. fn main()
  12. {
  13. let filter_a = true;
  14. let filter_b = true;
  15.  
  16.  
  17.  
  18. let items = vec![ Foo { slot_no: 1, value: 1 ,have_a : 1, have_b :1},
  19. Foo { slot_no: 1, value :2 ,have_a : 0, have_b :0},
  20. Foo { slot_no: 1, value :3,have_a : 1, have_b :1},
  21. Foo { slot_no: 1, value :4,have_a : 1, have_b :0},
  22. Foo { slot_no: 2, value :2,have_a : 0, have_b :0},
  23. Foo { slot_no: 2, value :1234,have_a : 1, have_b :0},
  24. Foo { slot_no: 3, value :12345,have_a : 1, have_b :1},
  25. Foo { slot_no: 3, value :23456,have_a : 1, have_b :0}];
  26.  
  27. let filter = |item: &Foo| (filter_a && item.have_a != 1) | (filter_b && item.have_b != 1);
  28.  
  29. let result = items.iter().filter(|item| filter(item));
  30. println!("{:?}", result.collect::<Vec<_>>())
  31.  
  32.  
  33. }
Add Comment
Please, Sign In to add comment