I'm trying to implement an iterator for a struct:
struct A {
x: Option<String>,
y: Option<String>,
z: String,
index: usize,
}
impl Iterator for A {
type Item = String;
fn next(&mut self) -> Option<Self::Item> {
let result = match self.index {
0 => /* **magic deciding thing for self.x** */,
1 => /* **magic deciding thing for self.y** */,
2 => String,
_ => return None,
};
self.index += 1;
Some(result)
}
}
Is there any way to always increment index
, and then exit the function if the value in x
or y
is None
, otherwise unwrap Some()
and carry on as usual? There are no default values I can return.