Hello,
Sorry in advance for the dumb question. This feels like it should be possible but I can't figure out the right way to bound the returned object so it can compile.
Any help is very much appreciated.
struct MyContainer {
records : Vec<String>
}
struct MyElementPointer<'a> {
container : &'a MyContainer,
record : &'a String
}
impl MyContainer {
pub fn iter<'incoming>(&'incoming self) -> impl Iterator<Item=MyElementPointer<'incoming>> + 'incoming {
self.records.iter().map(|record| MyElementPointer{container : &self, record : record})
}
}
fn main() {
let my_container = MyContainer{records : vec!["one".to_string(), "two".to_string(), "three".to_string()]};
for pointer in my_container.iter() {
println!("{} of {}", pointer.record, pointer.container.records.len());
}
}
Thank you in advance.