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
5 changes: 2 additions & 3 deletions arrow-array/src/array/boolean_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,8 @@ impl BooleanArray {
}
}

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

impl Array for BooleanArray {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl Array for BooleanArray {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +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> {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl<T: ByteArrayType> Array for GenericByteArray<T> {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/byte_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,9 +885,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> {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl<T: ByteViewType + ?Sized> Array for GenericByteViewArray<T> {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
9 changes: 3 additions & 6 deletions arrow-array/src/array/dictionary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,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> {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl<T: ArrowDictionaryKeyType> Array for DictionaryArray<T> {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down Expand Up @@ -853,9 +852,7 @@ 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> {
unsafe impl<K: ArrowDictionaryKeyType, V: Sync> Array for TypedDictionaryArray<'_, K, V> {
fn as_any(&self) -> &dyn Any {
self.dictionary
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/fixed_size_binary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,8 @@ impl std::fmt::Debug for FixedSizeBinaryArray {
}
}

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

impl Array for FixedSizeBinaryArray {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl Array for FixedSizeBinaryArray {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,8 @@ impl From<FixedSizeListArray> for ArrayData {
}
}

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

impl Array for FixedSizeListArray {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl Array for FixedSizeListArray {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,8 @@ impl<OffsetSize: OffsetSizeTrait> GenericListArray<OffsetSize> {
}
}

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

impl<OffsetSize: OffsetSizeTrait> Array for GenericListArray<OffsetSize> {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl<OffsetSize: OffsetSizeTrait> Array for GenericListArray<OffsetSize> {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/list_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +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> {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl<OffsetSize: OffsetSizeTrait> Array for GenericListViewArray<OffsetSize> {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/map_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,8 @@ impl MapArray {
}
}

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

impl Array for MapArray {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl Array for MapArray {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
25 changes: 11 additions & 14 deletions arrow-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,17 @@ 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)
///
/// 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 {
/// # Safety
///
/// Implementations of this trait must ensure that all methods implementations comply with
/// the Arrow specification. No safety guards are placed and failing to comply with it can
/// translate into panics or undefined behavior. For example, a value computed based on `len`
/// may be used as a direct index into memory regions without checks.
///
/// Use it at your own risk knowing that this trait might be sealed in the future.
pub unsafe trait Array: std::fmt::Debug + Send + Sync {
/// Returns the array as [`Any`] so that it can be
/// downcasted to a specific implementation.
///
Expand Down Expand Up @@ -351,10 +350,8 @@ pub trait Array: std::fmt::Debug + Send + Sync + private::Sealed {
/// 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 {
unsafe impl Array for ArrayRef {
fn as_any(&self) -> &dyn Any {
self.as_ref().as_any()
}
Expand Down Expand Up @@ -433,7 +430,7 @@ impl Array for ArrayRef {
}
}

impl<T: Array> Array for &T {
unsafe impl<T: Array> Array for &T {
fn as_any(&self) -> &dyn Any {
T::as_any(self)
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/null_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ impl NullArray {
}
}

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

impl Array for NullArray {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl Array for NullArray {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,9 +1186,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> {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl<T: ArrowPrimitiveType> Array for PrimitiveArray<T> {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
10 changes: 4 additions & 6 deletions arrow-array/src/array/run_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,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> {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl<T: RunEndIndexType> Array for RunArray<T> {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down Expand Up @@ -531,9 +530,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> {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl<R: RunEndIndexType, V: Sync> Array for TypedRunArray<'_, R, V> {
fn as_any(&self) -> &dyn Any {
self.run_array
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/struct_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,8 @@ impl TryFrom<Vec<(&str, ArrayRef)>> for StructArray {
}
}

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

impl Array for StructArray {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl Array for StructArray {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
5 changes: 2 additions & 3 deletions arrow-array/src/array/union_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,8 @@ impl From<UnionArray> for ArrayData {
}
}

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

impl Array for UnionArray {
/// SAFETY: Correctly implements the contract of Arrow Arrays
unsafe impl Array for UnionArray {
fn as_any(&self) -> &dyn Any {
self
}
Expand Down
Loading