diff --git a/src/array/specification.rs b/src/array/specification.rs index 1edcb70653f..d61735ce8e1 100644 --- a/src/array/specification.rs +++ b/src/array/specification.rs @@ -4,11 +4,15 @@ use num_traits::Num; use crate::types::Index; -/// Trait describing types that can be used as offsets as per Arrow specification. -/// This trait is only implemented for `i32` and `i64`, the two sizes part of the specification. -/// # Safety -/// Do not implement. -pub unsafe trait Offset: Index + Num + Ord + num_traits::CheckedAdd { +mod private { + pub trait Sealed {} + + impl Sealed for i32 {} + impl Sealed for i64 {} +} + +/// Sealed trait describing types that can be used as offsets in Arrow (`i32` and `i64`). +pub trait Offset: private::Sealed + Index + Num + Ord + num_traits::CheckedAdd { /// Whether it is `i32` or `i64` fn is_large() -> bool; @@ -19,7 +23,7 @@ pub unsafe trait Offset: Index + Num + Ord + num_traits::CheckedAdd { fn from_isize(value: isize) -> Option; } -unsafe impl Offset for i32 { +impl Offset for i32 { #[inline] fn is_large() -> bool { false @@ -36,7 +40,7 @@ unsafe impl Offset for i32 { } } -unsafe impl Offset for i64 { +impl Offset for i64 { #[inline] fn is_large() -> bool { true diff --git a/src/io/parquet/write/levels.rs b/src/io/parquet/write/levels.rs index ed9fe9e106b..725ebc2c96f 100644 --- a/src/io/parquet/write/levels.rs +++ b/src/io/parquet/write/levels.rs @@ -148,7 +148,7 @@ impl Iterator for DefLevelsIter<'_, O> { #[derive(Debug)] pub struct NestedInfo<'a, O: Offset> { - is_optional: bool, + _is_optional: bool, offsets: &'a [O], validity: Option<&'a Bitmap>, } @@ -156,7 +156,7 @@ pub struct NestedInfo<'a, O: Offset> { impl<'a, O: Offset> NestedInfo<'a, O> { pub fn new(offsets: &'a [O], validity: Option<&'a Bitmap>, is_optional: bool) -> Self { Self { - is_optional, + _is_optional: is_optional, offsets, validity, } diff --git a/src/types/mod.rs b/src/types/mod.rs index a20523d67f8..3ea5afd6e97 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -24,15 +24,33 @@ pub trait NaturalDataType { const DATA_TYPE: DataType; } +mod private { + pub trait Sealed {} + + impl Sealed for u8 {} + impl Sealed for u16 {} + impl Sealed for u32 {} + impl Sealed for u64 {} + impl Sealed for i8 {} + impl Sealed for i16 {} + impl Sealed for i32 {} + impl Sealed for i64 {} + impl Sealed for i128 {} + impl Sealed for f32 {} + impl Sealed for f64 {} + impl Sealed for super::days_ms {} + impl Sealed for super::months_days_ns {} +} + /// describes whether a [`DataType`] is valid. -pub unsafe trait Relation { +pub trait Relation: private::Sealed { /// Whether `data_type` is a valid [`DataType`]. fn is_valid(data_type: &DataType) -> bool; } macro_rules! create_relation { ($native_ty:ty, $physical_ty:expr) => { - unsafe impl Relation for $native_ty { + impl Relation for $native_ty { #[inline] fn is_valid(data_type: &DataType) -> bool { data_type.to_physical_type() == $physical_ty @@ -49,11 +67,10 @@ macro_rules! natural_type { }; } -/// Declares any type that can be allocated, serialized and deserialized by this crate. -/// All data-heavy memory operations are implemented for this trait alone. -/// # Safety -/// Do not implement. -pub unsafe trait NativeType: +/// Sealed trait that implemented by all types that can be allocated, +/// serialized and deserialized by this crate. +/// All O(N) in-memory allocations are implemented for this trait alone. +pub trait NativeType: Relation + NaturalDataType + Send @@ -89,7 +106,7 @@ pub unsafe trait NativeType: macro_rules! native { ($type:ty) => { - unsafe impl NativeType for $type { + impl NativeType for $type { type Bytes = [u8; std::mem::size_of::()]; #[inline] fn to_le_bytes(&self) -> Self::Bytes { @@ -166,7 +183,7 @@ impl std::fmt::Display for days_ms { } } -unsafe impl NativeType for days_ms { +impl NativeType for days_ms { type Bytes = [u8; 8]; #[inline] fn to_le_bytes(&self) -> Self::Bytes { @@ -266,7 +283,7 @@ impl std::fmt::Display for months_days_ns { } } -unsafe impl NativeType for months_days_ns { +impl NativeType for months_days_ns { type Bytes = [u8; 16]; #[inline] fn to_le_bytes(&self) -> Self::Bytes {