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
use crate::Matches;
pub type Guess<'a> = (&'a str, Matches);
pub struct StateIter<'a> {
pub(crate) solution: &'a str,
pub(crate) guesses: std::slice::Iter<'a, String>,
}
impl<'a> Iterator for StateIter<'a> {
type Item = Guess<'a>;
fn next(&mut self) -> Option<Self::Item> {
self.guesses
.next()
.map(|input| (input.as_str(), crate::diff(&*input, self.solution)))
}
}
impl<'a> DoubleEndedIterator for StateIter<'a> {
fn next_back(&mut self) -> Option<Self::Item> {
self.guesses
.next_back()
.map(|input| (input.as_str(), crate::diff(&*input, self.solution)))
}
}