vortex_array/vtable/
mod.rs

1//! This module contains the VTable definitions for a Vortex Array.
2
3use std::fmt::{Debug, Display, Formatter};
4use std::hash::{Hash, Hasher};
5
6mod compute;
7mod serde;
8mod statistics;
9
10pub use compute::*;
11pub use serde::*;
12pub use statistics::*;
13
14use crate::Array;
15use crate::arcref::ArcRef;
16use crate::encoding::EncodingId;
17
18/// A reference to an array VTable, either static or arc'd.
19pub type VTableRef = ArcRef<dyn EncodingVTable>;
20
21/// Dyn-compatible VTable trait for a Vortex array encoding.
22///
23/// This trait provides extension points for arrays to implement various features of Vortex.
24/// It is split into multiple sub-traits to make it easier for consumers to break up the
25/// implementation, as well as to allow for optional implementation of certain features, for example
26/// compute functions.
27pub trait EncodingVTable:
28    'static
29    + Sync
30    + Send
31    + ComputeVTable
32    + for<'a> SerdeVTable<&'a dyn Array>
33    + for<'a> StatisticsVTable<&'a dyn Array>
34{
35    /// Return the ID for this encoding implementation.
36    fn id(&self) -> EncodingId;
37}
38
39impl PartialEq for dyn EncodingVTable + '_ {
40    fn eq(&self, other: &Self) -> bool {
41        self.id() == other.id()
42    }
43}
44
45impl Eq for dyn EncodingVTable + '_ {}
46
47impl Hash for dyn EncodingVTable + '_ {
48    fn hash<H: Hasher>(&self, state: &mut H) {
49        self.id().hash(state)
50    }
51}
52
53impl Debug for dyn EncodingVTable + '_ {
54    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
55        write!(f, "{}", self.id())
56    }
57}
58
59impl Display for dyn EncodingVTable + '_ {
60    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
61        write!(f, "{}", self.id())
62    }
63}