Skip to content

Commit 46d9e78

Browse files
Add Iterator subtraits
1 parent d2241d7 commit 46d9e78

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pgrx-tests/src/tests/array_borrowed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn borrow_sum_array_i32(values: &FlatArray<'_, i32>) -> i32 {
2222
// we implement it this way so we can trap an overflow (as we have a test for this) and
2323
// catch it correctly in both --debug and --release modes
2424
let mut sum = 0_i32;
25-
for v in values.iter() {
25+
for v in values {
2626
let v = v.into_option().copied().unwrap_or(0);
2727
let (val, overflow) = sum.overflowing_add(v);
2828
if overflow {

pgrx/src/array.rs

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::toast::{Toast, Toasty};
2020
use crate::{layout, pg_sys, varlena};
2121
use bitvec::ptr::{self as bitptr, BitPtr, BitPtrError, Const, Mut};
2222
use bitvec::slice::{self as bitslice, BitSlice};
23+
use core::iter::{ExactSizeIterator, FusedIterator};
2324
use core::marker::PhantomData;
2425
use core::ptr::{self, NonNull};
2526
use core::{ffi, mem, slice};
@@ -257,6 +258,20 @@ where
257258
}
258259
}
259260

261+
impl<'arr, 'mcx, T> IntoIterator for &'arr FlatArray<'mcx, T>
262+
where
263+
T: ?Sized + BorrowDatum,
264+
{
265+
type IntoIter = ArrayIter<'arr, T>;
266+
type Item = Nullable<&'arr T>;
267+
fn into_iter(self) -> Self::IntoIter {
268+
self.iter()
269+
}
270+
}
271+
272+
impl<'arr, T> ExactSizeIterator for ArrayIter<'arr, T> where T: ?Sized + BorrowDatum {}
273+
impl<'arr, T> FusedIterator for ArrayIter<'arr, T> where T: ?Sized + BorrowDatum {}
274+
260275
/**
261276
An aligned, dereferenceable `NonNull<ArrayType>` with low-level accessors.
262277

0 commit comments

Comments
 (0)