-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provide lazy iterator implementation #449
Conversation
Hi! This is definitely interesting, I'll be looking over the code in detail in the next few days. Just a clarification, when you said
that was a typo for
correct? We're strict about maintaining backwards compatibility. |
Yes, sorry that's correct. The only publicly visible change is the return type of the I'm not opposed to changing the name of the new (this) iterator and putting back a shim implementation with this name and the legacy functionality, though I don't know what things should be named (my inclination would be to call this
Oh, I know ;) |
src/raw/iter.rs
Outdated
self.size | ||
} | ||
|
||
pub fn key(&self) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason to return the string as copy here rather than the ref?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, good call
@@ -275,7 +275,10 @@ impl<'a> Iterator for RawArrayIter<'a> { | |||
|
|||
fn next(&mut self) -> Option<Result<RawBsonRef<'a>>> { | |||
match self.inner.next() { | |||
Some(Ok((_, v))) => Some(Ok(v)), | |||
Some(Ok(elem)) => match elem.value() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be Some(Ok(elem)) => Some(elem.value())
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup!
src/raw/document.rs
Outdated
@@ -577,10 +594,10 @@ impl TryFrom<&RawDocument> for crate::Document { | |||
} | |||
|
|||
impl<'a> IntoIterator for &'a RawDocument { | |||
type IntoIter = Iter<'a>; | |||
type IntoIter = Box<dyn Iterator<Item = Self::Item> + 'a>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this is a breaking change. I think this can be solved by what you suggested in the conversation - keep the existing functionality named Iter
and call the new one RawIter
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alas, easy enough done
It looks like this fails the fuzz test; this program reproduces the failure:
|
Nice! Thanks for the review. I'll look at this this weekend or early next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the review; I made the changes and fixed the fuzz test.
src/raw/iter.rs
Outdated
self.size | ||
} | ||
|
||
pub fn key(&self) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, good call
@@ -275,7 +275,10 @@ impl<'a> Iterator for RawArrayIter<'a> { | |||
|
|||
fn next(&mut self) -> Option<Result<RawBsonRef<'a>>> { | |||
match self.inner.next() { | |||
Some(Ok((_, v))) => Some(Ok(v)), | |||
Some(Ok(elem)) => match elem.value() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup!
src/raw/document.rs
Outdated
@@ -577,10 +594,10 @@ impl TryFrom<&RawDocument> for crate::Document { | |||
} | |||
|
|||
impl<'a> IntoIterator for &'a RawDocument { | |||
type IntoIter = Iter<'a>; | |||
type IntoIter = Box<dyn Iterator<Item = Self::Item> + 'a>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alas, easy enough done
This fails the fuzzer with different input ( |
Ok, this time I think I have it. |
Still failing, I'm afraid ( |
I fixed it again, ran the fuzz test on my laptop for a while, nothing popped, and everything else passed (though my laptop is linux, it's not un-weird so I'm not sure what makes sense to validate.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Tagging in Isabel for review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thank you for the contribution!
Thanks @isabelatkinson @abr-egn! Do you schedule merges for things like this? Is there a regular release cadence for these libraries? Cheers, |
We don't have a specific release schedule, but I anticipate releasing 2.9.0 with this included in a week or so. |
Introduces a
RawElement
type which will can be used to lazily resolve bson values during iteration.This does not change the functionality of any existing interfaces for compatibility concerns, (though the
iter()
functions do return different types) and theIntoIter
implementations changed, but semantically it's all the same.Happy to make changes if ya'll are interested. in this :)