I've got a problem with lifetime specifiers in Rust.
I have a type Foo
that holds a vector of Strings. It should also implement the Iterator
trait, returning objects that hold a reference to Strings in Foo
.
see code example
What should the lifetime '?
be? How can I tell the Rust compiler that this works? Or is this entirely impossible or against some of Rust's idioms? What would be the appropriate workaround?
Code example:
struct Foo {
strings: Vec<String>,
}
impl Foo {
fn new(strings: Vec<String>) -> Self {
Self { strings }
}
}
struct Bar<'a> {
ref: &'a String,
}
impl Iterator for Foo {
type Item = Bar<'?>;
fn next(&mut self) -> Option<Self::Item> {
todo!();
}
}