Skip to content
Closed
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
31 changes: 31 additions & 0 deletions arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,37 @@ impl<'a> StringArrayType<'a> for &'a StringViewArray {
}
}

/// A trait for Arrow Binary Arrays, currently the following types are supported:
/// - `BinaryArray`
/// - `LargeBinaryArray`
/// - `BinaryViewArray`
/// - `FixedSizeBinaryArray`
///
/// This trait helps to abstract over the different types of binary arrays
/// so that we don't need to duplicate the implementation for each type.
pub trait BinaryArrayType<'a>: ArrayAccessor<Item = &'a [u8]> + Sized {
/// Constructs a new iterator
fn iter(&self) -> ArrayIter<Self>;
}

impl<'a, O: OffsetSizeTrait> BinaryArrayType<'a> for &'a GenericBinaryArray<O> {
fn iter(&self) -> ArrayIter<Self> {
GenericBinaryArray::<O>::iter(self)
}
}

impl<'a> BinaryArrayType<'a> for &'a BinaryViewArray {
fn iter(&self) -> ArrayIter<Self> {
BinaryViewArray::iter(self)
}
}

impl<'a> BinaryArrayType<'a> for &'a FixedSizeBinaryArray {
fn iter(&self) -> ArrayIter<Self> {
FixedSizeBinaryArray::iter(self)
}
}

impl PartialEq for dyn Array + '_ {
fn eq(&self, other: &Self) -> bool {
self.to_data().eq(&other.to_data())
Expand Down