alamb commented on code in PR #2133:
URL: https://github.com/apache/arrow-rs/pull/2133#discussion_r927744704


##########
arrow/src/array/iterator.rs:
##########
@@ -15,36 +15,37 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use crate::array::array::ArrayAccessor;
 use crate::array::BasicDecimalArray;
-use crate::datatypes::ArrowPrimitiveType;
 
 use super::{
-    Array, ArrayRef, BooleanArray, Decimal128Array, GenericBinaryArray, 
GenericListArray,
-    GenericStringArray, OffsetSizeTrait, PrimitiveArray,
+    Array, BooleanArray, Decimal128Array, GenericBinaryArray, GenericListArray,
+    GenericStringArray, PrimitiveArray,
 };
 
-/// an iterator that returns Some(T) or None, that can be used on any 
PrimitiveArray
+/// an iterator that returns Some(T) or None, that can be used on any 
[`ArrayAccessor`]
 // Note: This implementation is based on std's [Vec]s' [IntoIter].
 #[derive(Debug)]
-pub struct PrimitiveIter<'a, T: ArrowPrimitiveType> {
-    array: &'a PrimitiveArray<T>,
+pub struct ArrayIter<T: ArrayAccessor> {

Review Comment:
   👍  this is very cool



##########
arrow/src/array/array.rs:
##########
@@ -297,6 +297,79 @@ impl Array for ArrayRef {
     }
 }
 
+impl<'a, T: Array> Array for &'a T {
+    fn as_any(&self) -> &dyn Any {
+        T::as_any(self)
+    }
+
+    fn data(&self) -> &ArrayData {
+        T::data(self)
+    }
+
+    fn into_data(self) -> ArrayData {
+        self.data().clone()
+    }
+
+    fn data_ref(&self) -> &ArrayData {
+        T::data_ref(self)
+    }
+
+    fn data_type(&self) -> &DataType {
+        T::data_type(self)
+    }
+
+    fn slice(&self, offset: usize, length: usize) -> ArrayRef {
+        T::slice(self, offset, length)
+    }
+
+    fn len(&self) -> usize {
+        T::len(self)
+    }
+
+    fn is_empty(&self) -> bool {
+        T::is_empty(self)
+    }
+
+    fn offset(&self) -> usize {
+        T::offset(self)
+    }
+
+    fn is_null(&self, index: usize) -> bool {
+        T::is_null(self, index)
+    }
+
+    fn is_valid(&self, index: usize) -> bool {
+        T::is_valid(self, index)
+    }
+
+    fn null_count(&self) -> usize {
+        T::null_count(self)
+    }
+
+    fn get_buffer_memory_size(&self) -> usize {
+        T::get_buffer_memory_size(self)
+    }
+
+    fn get_array_memory_size(&self) -> usize {
+        T::get_array_memory_size(self)
+    }
+
+    fn to_raw(
+        &self,
+    ) -> Result<(*const ffi::FFI_ArrowArray, *const ffi::FFI_ArrowSchema)> {
+        T::to_raw(self)
+    }
+}
+
+/// A generic trait for accessing the values of an [`Array`]
+pub trait ArrayAccessor: Array {

Review Comment:
   👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to