1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::iter::FilterMap;
#[derive(Debug)]
pub enum CandidateSolution<T = usize> {
Incomplete,
Sat(Vec<T>),
Unsat(Vec<T>),
}
#[derive(Debug)]
pub enum Solution<T = usize> {
Sat(Vec<T>),
Unsat(Vec<T>),
}
type OptionalSat = Option<Vec<usize>>;
pub trait IterSolveExt: Iterator<Item = CandidateSolution> + Sized {
fn solution_iter(self) -> FilterMap<Self, fn(CandidateSolution) -> Option<Solution>> {
self.filter_map(|s| match s {
CandidateSolution::Sat(sat) => Some(Solution::Sat(sat)),
CandidateSolution::Unsat(unsat) => Some(Solution::Unsat(unsat)),
CandidateSolution::Incomplete => None,
})
}
fn sat_iter(self) -> FilterMap<Self, fn(CandidateSolution) -> OptionalSat> {
self.filter_map(|s| match s {
CandidateSolution::Sat(sat) => Some(sat),
_ => None,
})
}
}
impl<T: Iterator<Item = CandidateSolution>> IterSolveExt for T {}