Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate itertools;
- use itertools::Itertools;
- #[derive(Debug)]
- struct Foo
- {
- slot_no: i32,
- have_a : i32,
- have_b: i32,
- value : i32
- }
- fn main()
- {
- let filter_a = true;
- let filter_b = true;
- let items = vec![ Foo { slot_no: 1, value: 1 ,have_a : 1, have_b :1},
- Foo { slot_no: 1, value :2 ,have_a : 0, have_b :0},
- Foo { slot_no: 1, value :3,have_a : 1, have_b :1},
- Foo { slot_no: 1, value :4,have_a : 1, have_b :0},
- Foo { slot_no: 2, value :2,have_a : 0, have_b :0},
- Foo { slot_no: 2, value :1234,have_a : 1, have_b :0},
- Foo { slot_no: 3, value :12345,have_a : 1, have_b :1},
- Foo { slot_no: 3, value :23456,have_a : 1, have_b :0}];
- let filter = |item: &Foo| (filter_a && item.have_a != 1) | (filter_b && item.have_b != 1);
- let result = items.iter().filter(|item| filter(item));
- println!("{:?}", result.collect::<Vec<_>>())
- }
Add Comment
Please, Sign In to add comment