use crate::array::ArrayType;
use std::{fmt::Debug, mem};
#[cfg(feature = "arrow-rs")]
mod arrow_rs {
pub use arrow_buffer::ArrowNativeType as _arrow_rs_trait;
}
#[cfg(not(feature = "arrow-rs"))]
mod arrow_rs {
pub trait Type {}
impl<T> Type for T {}
pub use Type as _arrow_rs_trait;
}
use arrow_rs::_arrow_rs_trait;
pub trait FixedSize:
ArrayType + Copy + Debug + Sized + sealed::Sealed + 'static + _arrow_rs_trait
{
const SIZE: usize = mem::size_of::<Self>();
}
mod sealed {
pub trait Sealed {}
impl<T> Sealed for T where T: super::FixedSize {}
}
impl FixedSize for i8 {}
impl FixedSize for i16 {}
impl FixedSize for i32 {}
impl FixedSize for i64 {}
impl FixedSize for i128 {}
impl FixedSize for u8 {}
impl FixedSize for u16 {}
impl FixedSize for u32 {}
impl FixedSize for u64 {}
#[cfg(not(feature = "arrow-rs"))]
impl FixedSize for u128 {}
#[cfg(not(feature = "arrow-rs"))]
impl FixedSize for isize {}
#[cfg(not(feature = "arrow-rs"))]
impl FixedSize for usize {}
impl FixedSize for f32 {}
impl FixedSize for f64 {}
#[cfg(not(feature = "arrow-rs"))]
impl<const N: usize, T: super::FixedSize> FixedSize for [T; N] {}
#[cfg(test)]
mod tests {
use super::FixedSize;
#[test]
fn size() {
assert_eq!(u8::SIZE, 1);
#[cfg(not(feature = "arrow-rs"))]
assert_eq!(<[u16; 21]>::SIZE, 42);
#[cfg(not(feature = "arrow-rs"))]
assert_eq!(<[u8; 1234]>::SIZE, 1234);
}
}