polars_arrow/types/
mod.rs

1//! Sealed traits and implementations to handle all _physical types_ used in this crate.
2//!
3//! Most physical types used in this crate are native Rust types, such as `i32`.
4//! The trait [`NativeType`] describes the interfaces required by this crate to be conformant
5//! with Arrow.
6//!
7//! Every implementation of [`NativeType`] has an associated variant in [`PrimitiveType`],
8//! available via [`NativeType::PRIMITIVE`].
9//! Combined, these allow structs generic over [`NativeType`] to be trait objects downcastable
10//! to concrete implementations based on the matched [`NativeType::PRIMITIVE`] variant.
11//!
12//! Another important trait in this module is [`Offset`], the subset of [`NativeType`] that can
13//! be used in Arrow offsets (`i32` and `i64`).
14//!
15//! Another important trait in this module is [`BitChunk`], describing types that can be used to
16//! represent chunks of bits (e.g. 8 bits via `u8`, 16 via `u16`), and [`BitChunkIter`],
17//! that can be used to iterate over bitmaps in [`BitChunk`]s according to
18//! Arrow's definition of bitmaps.
19
20mod aligned_bytes;
21pub use aligned_bytes::*;
22mod bit_chunk;
23pub use bit_chunk::{BitChunk, BitChunkIter, BitChunkOnes};
24mod index;
25pub use index::*;
26mod native;
27pub use native::*;
28mod offset;
29pub use offset::*;
30#[cfg(feature = "serde")]
31use serde::{Deserialize, Serialize};
32
33/// The set of all implementations of the sealed trait [`NativeType`].
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
35#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
36pub enum PrimitiveType {
37    /// A signed 8-bit integer.
38    Int8,
39    /// A signed 16-bit integer.
40    Int16,
41    /// A signed 32-bit integer.
42    Int32,
43    /// A signed 64-bit integer.
44    Int64,
45    /// A signed 128-bit integer.
46    Int128,
47    /// A signed 256-bit integer.
48    Int256,
49    /// An unsigned 8-bit integer.
50    UInt8,
51    /// An unsigned 16-bit integer.
52    UInt16,
53    /// An unsigned 32-bit integer.
54    UInt32,
55    /// An unsigned 64-bit integer.
56    UInt64,
57    /// An unsigned 128-bit integer.
58    UInt128,
59    /// A 16-bit floating point number.
60    Float16,
61    /// A 32-bit floating point number.
62    Float32,
63    /// A 64-bit floating point number.
64    Float64,
65    /// Two i32 representing days and ms
66    DaysMs,
67    /// months_days_ns(i32, i32, i64)
68    MonthDayNano,
69}
70
71mod private {
72    use crate::array::View;
73
74    pub trait Sealed {}
75
76    impl Sealed for u8 {}
77    impl Sealed for u16 {}
78    impl Sealed for u32 {}
79    impl Sealed for u64 {}
80    impl Sealed for i8 {}
81    impl Sealed for i16 {}
82    impl Sealed for i32 {}
83    impl Sealed for i64 {}
84    impl Sealed for i128 {}
85    impl Sealed for u128 {}
86    impl Sealed for super::i256 {}
87    impl Sealed for super::f16 {}
88    impl Sealed for f32 {}
89    impl Sealed for f64 {}
90    impl Sealed for super::days_ms {}
91    impl Sealed for super::months_days_ns {}
92    impl Sealed for View {}
93}