@@ -32,7 +32,14 @@ use crate::scalar::ScalarValue;
3232/// [`try_with_vtable()`]: ExtDType::try_with_vtable
3333/// [`erased()`]: ExtDType::erased
3434#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
35- pub struct ExtDType < V : ExtVTable > ( pub ( super ) Arc < ExtDTypeInner < V > > ) ;
35+ pub struct ExtDType < V : ExtVTable > {
36+ /// The extension dtype vtable.
37+ vtable : V ,
38+ /// The extension dtype metadata.
39+ metadata : V :: Metadata ,
40+ /// The underlying storage dtype.
41+ storage_dtype : DType ,
42+ }
3643
3744/// Convenience implementation for zero-sized VTables (or VTables that implement `Default`).
3845impl < V : ExtVTable + Default > ExtDType < V > {
@@ -49,60 +56,43 @@ impl<V: ExtVTable> ExtDType<V> {
4956 metadata : V :: Metadata ,
5057 storage_dtype : DType ,
5158 ) -> VortexResult < Self > {
52- vtable. validate_dtype ( & metadata, & storage_dtype) ?;
53-
54- Ok ( Self ( Arc :: new ( ExtDTypeInner :: < V > {
59+ let this = Self {
5560 vtable,
5661 metadata,
5762 storage_dtype,
58- } ) ) )
63+ } ;
64+
65+ this. vtable . validate_dtype ( & this) ?;
66+
67+ Ok ( this)
5968 }
6069
6170 /// Returns the identifier of the extension type.
6271 pub fn id ( & self ) -> ExtId {
63- self . 0 . vtable . id ( )
72+ self . vtable . id ( )
6473 }
6574
6675 /// Returns the vtable of the extension type.
6776 pub fn vtable ( & self ) -> & V {
68- & self . 0 . vtable
77+ & self . vtable
6978 }
7079
7180 /// Returns the metadata of the extension type.
7281 pub fn metadata ( & self ) -> & V :: Metadata {
73- & self . 0 . metadata
82+ & self . metadata
7483 }
7584
7685 /// Returns the storage dtype of the extension type.
7786 pub fn storage_dtype ( & self ) -> & DType {
78- & self . 0 . storage_dtype
87+ & self . storage_dtype
7988 }
8089
8190 /// Erase the concrete type information, returning a type-erased extension dtype.
8291 pub fn erased ( self ) -> ExtDTypeRef {
83- ExtDTypeRef ( self . 0 )
92+ ExtDTypeRef ( Arc :: new ( self ) )
8493 }
8594}
8695
87- // ---------------------------------------------------------------------------
88- // Private inner struct + sealed trait
89- // ---------------------------------------------------------------------------
90-
91- /// The private inner representation of an extension dtype, pairing a vtable with its metadata
92- /// and storage dtype.
93- ///
94- /// This is the sole implementor of [`DynExtDType`], enabling [`ExtDTypeRef`] to safely downcast
95- /// back to the concrete vtable type via [`Any`].
96- #[ derive( Debug , PartialEq , Eq , Hash ) ]
97- pub ( super ) struct ExtDTypeInner < V : ExtVTable > {
98- /// The extension dtype vtable.
99- pub ( super ) vtable : V ,
100- /// The extension dtype metadata.
101- pub ( super ) metadata : V :: Metadata ,
102- /// The underlying storage dtype.
103- pub ( super ) storage_dtype : DType ,
104- }
105-
10696/// An object-safe, sealed trait encapsulating the behavior for extension dtypes.
10797///
10898/// This provides type-erased access to the extension dtype's identity, storage dtype, and
@@ -111,9 +101,9 @@ pub(super) trait DynExtDType: 'static + Send + Sync + super::sealed::Sealed {
111101 /// Returns `self` as a trait object for downcasting.
112102 fn as_any ( & self ) -> & dyn Any ;
113103 /// Returns the [`ExtId`] identifying this extension type.
114- fn id ( & self ) -> ExtId ;
104+ fn ext_id ( & self ) -> ExtId ;
115105 /// Returns a reference to the storage [`DType`].
116- fn storage_dtype ( & self ) -> & DType ;
106+ fn ext_storage_dtype ( & self ) -> & DType ;
117107 /// Returns the metadata as a trait object for downcasting.
118108 fn metadata_any ( & self ) -> & dyn Any ;
119109 /// Formats the metadata using [`Debug`].
@@ -135,16 +125,16 @@ pub(super) trait DynExtDType: 'static + Send + Sync + super::sealed::Sealed {
135125 -> fmt:: Result ;
136126}
137127
138- impl < V : ExtVTable > DynExtDType for ExtDTypeInner < V > {
128+ impl < V : ExtVTable > DynExtDType for ExtDType < V > {
139129 fn as_any ( & self ) -> & dyn Any {
140130 self
141131 }
142132
143- fn id ( & self ) -> ExtId {
133+ fn ext_id ( & self ) -> ExtId {
144134 self . vtable . id ( )
145135 }
146136
147- fn storage_dtype ( & self ) -> & DType {
137+ fn ext_storage_dtype ( & self ) -> & DType {
148138 & self . storage_dtype
149139 }
150140
@@ -186,19 +176,15 @@ impl<V: ExtVTable> DynExtDType for ExtDTypeInner<V> {
186176 }
187177
188178 fn value_validate ( & self , storage_value : & ScalarValue ) -> VortexResult < ( ) > {
189- self . vtable
190- . validate_scalar_value ( & self . metadata , & self . storage_dtype , storage_value)
179+ self . vtable . validate_scalar_value ( self , storage_value)
191180 }
192181
193182 fn value_display (
194183 & self ,
195184 f : & mut fmt:: Formatter < ' _ > ,
196185 storage_value : & ScalarValue ,
197186 ) -> fmt:: Result {
198- match self
199- . vtable
200- . unpack_native ( & self . metadata , & self . storage_dtype , storage_value)
201- {
187+ match self . vtable . unpack_native ( self , storage_value) {
202188 Ok ( native) => fmt:: Display :: fmt ( & native, f) ,
203189 Err ( _) => write ! (
204190 f,
0 commit comments