Lifetime-based iterator
Closed this issue · 2 comments
We would love to use StreamingIterator, but we are in a situation in which we need a lifetime on the item. We are implementing our own version similarly to this:
pub trait StreamingIterator {
type Item<'b>
where
Self: 'b;
fn get(&self) -> Option<Self::Item<'_>>;
}
That is, we return actually the item, rather than a reference to the item, and the item has a lifetime that we can use to return references inside the item.
It there any way StreamingIterator can be adapted to this case?
It would definitely be a breaking change to switch to GATs, and I think that would also come with some compiler limitations that don't affect the current &Item
style.
There are a few other crates that do this, often calling it "lending iterator" now to distinguish from async streams.
https://crates.io/search?q=lending+iterator
Thank you, we will look into it. Great create, in any case!