Having code like
#[derive(Debug)]
struct BinaryVec {
vec: Vec<u8>,
}
impl BinaryVec {
fn empty() -> BinaryVec {
BinaryVec { vec: Vec::new() }
}
fn push(&mut self, bit: u8) {
self.vec.push(bit);
}
}
I'd like to be able to iterate over the structure's vector without making it public. For example, to call it like:
let bin_vec = BinaryVec::empty();
bin_vec.push(1);
bin_vec.push(0);
bin_vec.push(1);
for el in bin_vec.iter() {
// do something with 1,0,1 elements
}
But I see that Iterator trait requires only next method which assumes the saved iter state in the structure.
Is there any way to directly pass vec iter through the higher level struct in Rust without adding new state related fields to the struct?