Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions arrow-array/src/array/boolean_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ impl BooleanArray {
}
}

impl super::private::Sealed for BooleanArray {}

impl Array for BooleanArray {
fn as_any(&self) -> &dyn Any {
self
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ impl<T: ByteArrayType> std::fmt::Debug for GenericByteArray<T> {
}
}

impl<T: ByteArrayType> super::private::Sealed for GenericByteArray<T> {}

impl<T: ByteArrayType> Array for GenericByteArray<T> {
fn as_any(&self) -> &dyn Any {
self
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/byte_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,8 @@ impl<T: ByteViewType + ?Sized> Debug for GenericByteViewArray<T> {
}
}

impl<T: ByteViewType + ?Sized> super::private::Sealed for GenericByteViewArray<T> {}

impl<T: ByteViewType + ?Sized> Array for GenericByteViewArray<T> {
fn as_any(&self) -> &dyn Any {
self
Expand Down
4 changes: 4 additions & 0 deletions arrow-array/src/array/dictionary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ impl<'a, T: ArrowDictionaryKeyType> FromIterator<&'a str> for DictionaryArray<T>
}
}

impl<T: ArrowDictionaryKeyType> super::private::Sealed for DictionaryArray<T> {}

impl<T: ArrowDictionaryKeyType> Array for DictionaryArray<T> {
fn as_any(&self) -> &dyn Any {
self
Expand Down Expand Up @@ -856,6 +858,8 @@ impl<'a, K: ArrowDictionaryKeyType, V> TypedDictionaryArray<'a, K, V> {
}
}

impl<K: ArrowDictionaryKeyType, V: Sync> super::private::Sealed for TypedDictionaryArray<'_, K, V> {}

impl<K: ArrowDictionaryKeyType, V: Sync> Array for TypedDictionaryArray<'_, K, V> {
fn as_any(&self) -> &dyn Any {
self.dictionary
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/fixed_size_binary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ impl std::fmt::Debug for FixedSizeBinaryArray {
}
}

impl super::private::Sealed for FixedSizeBinaryArray {}

impl Array for FixedSizeBinaryArray {
fn as_any(&self) -> &dyn Any {
self
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ impl From<FixedSizeListArray> for ArrayData {
}
}

impl super::private::Sealed for FixedSizeListArray {}

impl Array for FixedSizeListArray {
fn as_any(&self) -> &dyn Any {
self
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {
}
}

impl<OffsetSize: OffsetSizeTrait> super::private::Sealed for GenericListArray<OffsetSize> {}

impl<OffsetSize: OffsetSizeTrait> Array for GenericListArray<OffsetSize> {
fn as_any(&self) -> &dyn Any {
self
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/list_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ impl<OffsetSize: OffsetSizeTrait> ArrayAccessor for &GenericListViewArray<Offset
}
}

impl<OffsetSize: OffsetSizeTrait> super::private::Sealed for GenericListViewArray<OffsetSize> {}

impl<OffsetSize: OffsetSizeTrait> Array for GenericListViewArray<OffsetSize> {
fn as_any(&self) -> &dyn Any {
self
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/map_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ impl MapArray {
}
}

impl super::private::Sealed for MapArray {}

impl Array for MapArray {
fn as_any(&self) -> &dyn Any {
self
Expand Down
14 changes: 13 additions & 1 deletion arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,18 @@ pub use list_view_array::*;

use crate::iterator::ArrayIter;

mod private {
/// Private marker trait to ensure [`super::Array`] can not be implemented outside this crate
pub trait Sealed {}

impl<T: Sealed> Sealed for &T {}
}

/// An array in the [arrow columnar format](https://arrow.apache.org/docs/format/Columnar.html)
pub trait Array: std::fmt::Debug + Send + Sync {
///
/// This trait is sealed as it is not intended for custom array types, rather only
/// those defined in this crate.
pub trait Array: std::fmt::Debug + Send + Sync + private::Sealed {
/// Returns the array as [`Any`] so that it can be
/// downcasted to a specific implementation.
///
Expand Down Expand Up @@ -341,6 +351,8 @@ pub trait Array: std::fmt::Debug + Send + Sync {
/// A reference-counted reference to a generic `Array`
pub type ArrayRef = Arc<dyn Array>;

impl private::Sealed for ArrayRef {}

/// Ergonomics: Allow use of an ArrayRef as an `&dyn Array`
impl Array for ArrayRef {
fn as_any(&self) -> &dyn Any {
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/null_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ impl NullArray {
}
}

impl super::private::Sealed for NullArray {}

impl Array for NullArray {
fn as_any(&self) -> &dyn Any {
self
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,8 @@ impl<T: ArrowPrimitiveType> From<PrimitiveArray<T>> for ArrayData {
}
}

impl<T: ArrowPrimitiveType> super::private::Sealed for PrimitiveArray<T> {}

impl<T: ArrowPrimitiveType> Array for PrimitiveArray<T> {
fn as_any(&self) -> &dyn Any {
self
Expand Down
4 changes: 4 additions & 0 deletions arrow-array/src/array/run_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ impl<R: RunEndIndexType> From<RunArray<R>> for ArrayData {
}
}

impl<T: RunEndIndexType> super::private::Sealed for RunArray<T> {}

impl<T: RunEndIndexType> Array for RunArray<T> {
fn as_any(&self) -> &dyn Any {
self
Expand Down Expand Up @@ -519,6 +521,8 @@ impl<'a, R: RunEndIndexType, V> TypedRunArray<'a, R, V> {
}
}

impl<R: RunEndIndexType, V: Sync> super::private::Sealed for TypedRunArray<'_, R, V> {}

impl<R: RunEndIndexType, V: Sync> Array for TypedRunArray<'_, R, V> {
fn as_any(&self) -> &dyn Any {
self.run_array
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/struct_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ impl TryFrom<Vec<(&str, ArrayRef)>> for StructArray {
}
}

impl super::private::Sealed for StructArray {}

impl Array for StructArray {
fn as_any(&self) -> &dyn Any {
self
Expand Down
2 changes: 2 additions & 0 deletions arrow-array/src/array/union_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ impl From<UnionArray> for ArrayData {
}
}

impl super::private::Sealed for UnionArray {}

impl Array for UnionArray {
fn as_any(&self) -> &dyn Any {
self
Expand Down
Loading