What is the best way to implement different implementations of a trait on the same struct? Let's I have a struct containing items and I want to have different ways to iterate through them.
struct Batch {
items: Vec<u8>,
pos: usize,
}
impl Iterator [?? for one] for Batch {
fn next(&mut self) -> Option<u8> {
self.pos += 1;
Some(self.items[self.pos])
}
}
impl Iterator [?? for two] for Batch {
fn next(&mut self) -> Option<u8> {
self.pos += 2;
Some(self.items[self.pos])
}
}
So far I've used separate structs containing the original struct and each struct has its impl for the trait.
struct BatchIterOne {
batch: Batch
}
impl Iterator for BatchIterOne {...}
struct BatchIterTwo {
batch: Batch
}
impl Iterator for BatchIterTwo {...}
it works but feels a bit clunky. Is there a better way?