-
Notifications
You must be signed in to change notification settings - Fork 38
Thoughts on the current implementation of iterators #25
Comments
I like this idea, especially for rkv, which shouldn't be exposing footguns like
If we can, I'd preserve the current semantics of IterDup, which seem intuitive and ergonomic. There's discussion in danburkert#32 about using a StreamingIterator, which might work. |
Sounds good. I'd like to put this proposal on hold for following reasons:
|
Ok, sounds good, let's put this on hold for now! |
I faced issues with this when trying to return an The best solution I came up with is to use
Is this correct? Am I taking any risks here? Is there a better way? Regardless, it took me a while to arrive at this solution, for what I expect is a relatively common use case. This rather diminishes the "idiomatic and safe API" headline for the crate. It would be good to document this or at least give an example. I assume there's a good reason for not doing it, but it would be natural to have an API that takes the If
By the way, as far as I understand GATs have recently been stabilized in nightly, so a clean |
I've been attempting to include the
I'd welcome any suggestions, there must be an easier way to do this than to use self-referential types? I've tried a few variants with |
Yeah I am getting |
While trying to seek the solution to this potential optimization, I am more inclined to believe that the current iterator implementation on
Cursor
is problematic.Firstly, as @mykmelez pointed out here, it's fairly easy to run into panics if the consumer ignores the fact that iterators are derived from the underlying cursors, hence iterators can't outlive its cursors, whereas the current implementation can not enforce that. Although the iterators in rkv are implemented by bundling the iterator and the cursor together, since rkv exposes it via
pub use lmdb::Cursor
, it remains as a risk there.Secondly, allowing consumers to create iterators on an in-flight cursor could cause invalid (EINVAL) cursor states, which also complicate the error handling code. Imagine the consumer performs this on an empty store,
One way to fix this is to have iterators own the underlying cursors, and let the
Store(s)
be responsible for creating those iterators. This also requires a change on the dup iterators, which currently return a regular iterator on eachnext
call. If we'd like to keep this flexibility other than flatten everything, then it will need some kind of sharing of that cursor between iterators.Would love to hear your thoughts? @mykmelez
The text was updated successfully, but these errors were encountered: