Skip to content
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

Fixup iterator impls for Array #1115

Merged
merged 3 commits into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions pgrx/src/datum/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,18 +424,19 @@ impl<'a, T: FromDatum> Iterator for ArrayIntoIterator<'a, T> {
}

fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(self.array.nelems))
}

fn count(self) -> usize
where
Self: Sized,
{
self.array.nelems
// If asking for size, it's not clear if they want "actual size"
// or "size minus nulls"? Let's lower bound on 0 if nulls exist.
let left = self.array.nelems - self.curr;
if let NullKind::Strict(_) = self.array.null_slice {
(left, Some(left))
} else {
(0, Some(left))
}
}

fn nth(&mut self, n: usize) -> Option<Self::Item> {
self.array.get(n)
fn count(self) -> usize {
// TODO: This code is dangerously under-exercised in the test suite.
self.array.nelems - self.curr
}
}

Expand Down