@@ -110,11 +110,11 @@ impl From<u32> for LogicalTypeId {
110
110
111
111
/// DuckDB Logical Type.
112
112
/// <https://duckdb.org/docs/sql/data_types/overview>
113
- pub struct LogicalType {
113
+ pub struct LogicalTypeHandle {
114
114
pub ( crate ) ptr : duckdb_logical_type ,
115
115
}
116
116
117
- impl Debug for LogicalType {
117
+ impl Debug for LogicalTypeHandle {
118
118
/// Debug implementation for LogicalType
119
119
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
120
120
let id = self . id ( ) ;
@@ -134,7 +134,7 @@ impl Debug for LogicalType {
134
134
}
135
135
}
136
136
137
- impl Drop for LogicalType {
137
+ impl Drop for LogicalTypeHandle {
138
138
/// Drop implementation for LogicalType
139
139
fn drop ( & mut self ) {
140
140
if !self . ptr . is_null ( ) {
@@ -147,25 +147,25 @@ impl Drop for LogicalType {
147
147
}
148
148
}
149
149
150
- impl From < duckdb_logical_type > for LogicalType {
151
- /// Wrap a DuckDB logical type from C API
152
- fn from ( ptr : duckdb_logical_type ) -> Self {
153
- Self { ptr }
154
- }
155
- }
156
-
157
- impl LogicalType {
158
- /// Create a new [LogicalType] from [LogicalTypeId]
159
- pub fn new ( id : LogicalTypeId ) -> Self {
150
+ impl From < LogicalTypeId > for LogicalTypeHandle {
151
+ /// Create a new [LogicalTypeHandle] from [LogicalTypeId]
152
+ fn from ( id : LogicalTypeId ) -> Self {
160
153
unsafe {
161
154
Self {
162
155
ptr : duckdb_create_logical_type ( id as u32 ) ,
163
156
}
164
157
}
165
158
}
159
+ }
160
+
161
+ impl LogicalTypeHandle {
162
+ /// Create a DuckDB logical type from C API
163
+ pub ( crate ) unsafe fn new ( ptr : duckdb_logical_type ) -> Self {
164
+ Self { ptr }
165
+ }
166
166
167
167
/// Creates a map type from its child type.
168
- pub fn map ( key : & LogicalType , value : & LogicalType ) -> Self {
168
+ pub fn map ( key : & LogicalTypeHandle , value : & LogicalTypeHandle ) -> Self {
169
169
unsafe {
170
170
Self {
171
171
ptr : duckdb_create_map_type ( key. ptr , value. ptr ) ,
@@ -174,7 +174,7 @@ impl LogicalType {
174
174
}
175
175
176
176
/// Creates a list type from its child type.
177
- pub fn list ( child_type : & LogicalType ) -> Self {
177
+ pub fn list ( child_type : & LogicalTypeHandle ) -> Self {
178
178
unsafe {
179
179
Self {
180
180
ptr : duckdb_create_list_type ( child_type. ptr ) ,
@@ -183,7 +183,7 @@ impl LogicalType {
183
183
}
184
184
185
185
/// Creates an array type from its child type.
186
- pub fn array ( child_type : & LogicalType , array_size : u64 ) -> Self {
186
+ pub fn array ( child_type : & LogicalTypeHandle , array_size : u64 ) -> Self {
187
187
unsafe {
188
188
Self {
189
189
ptr : duckdb_create_array_type ( child_type. ptr , array_size) ,
@@ -213,7 +213,7 @@ impl LogicalType {
213
213
}
214
214
215
215
/// Make a `LogicalType` for `struct`
216
- pub fn struct_type ( fields : & [ ( & str , LogicalType ) ] ) -> Self {
216
+ pub fn struct_type ( fields : & [ ( & str , LogicalTypeHandle ) ] ) -> Self {
217
217
let keys: Vec < CString > = fields. iter ( ) . map ( |f| CString :: new ( f. 0 ) . unwrap ( ) ) . collect ( ) ;
218
218
let values: Vec < duckdb_logical_type > = fields. iter ( ) . map ( |it| it. 1 . ptr ) . collect ( ) ;
219
219
let name_ptrs = keys. iter ( ) . map ( |it| it. as_ptr ( ) ) . collect :: < Vec < * const c_char > > ( ) ;
@@ -230,7 +230,7 @@ impl LogicalType {
230
230
}
231
231
232
232
/// Make a `LogicalType` for `union`
233
- pub fn union_type ( fields : & [ ( & str , LogicalType ) ] ) -> Self {
233
+ pub fn union_type ( fields : & [ ( & str , LogicalTypeHandle ) ] ) -> Self {
234
234
let keys: Vec < CString > = fields. iter ( ) . map ( |f| CString :: new ( f. 0 ) . unwrap ( ) ) . collect ( ) ;
235
235
let values: Vec < duckdb_logical_type > = fields. iter ( ) . map ( |it| it. 1 . ptr ) . collect ( ) ;
236
236
let name_ptrs = keys. iter ( ) . map ( |it| it. as_ptr ( ) ) . collect :: < Vec < * const c_char > > ( ) ;
@@ -287,18 +287,18 @@ impl LogicalType {
287
287
_ => panic ! ( "not a struct or union" ) ,
288
288
}
289
289
} ;
290
- Self :: from ( c_logical_type)
290
+ unsafe { Self :: new ( c_logical_type) }
291
291
}
292
292
}
293
293
294
294
#[ cfg( test) ]
295
295
mod test {
296
- use crate :: core:: { LogicalType , LogicalTypeId } ;
296
+ use crate :: core:: { LogicalTypeHandle , LogicalTypeId } ;
297
297
298
298
#[ test]
299
299
fn test_struct ( ) {
300
- let fields = & [ ( "hello" , LogicalType :: new ( crate :: core:: LogicalTypeId :: Boolean ) ) ] ;
301
- let typ = LogicalType :: struct_type ( fields) ;
300
+ let fields = & [ ( "hello" , LogicalTypeHandle :: from ( crate :: core:: LogicalTypeId :: Boolean ) ) ] ;
301
+ let typ = LogicalTypeHandle :: struct_type ( fields) ;
302
302
303
303
assert_eq ! ( typ. num_children( ) , 1 ) ;
304
304
assert_eq ! ( typ. child_name( 0 ) , "hello" ) ;
@@ -307,7 +307,7 @@ mod test {
307
307
308
308
#[ test]
309
309
fn test_decimal ( ) {
310
- let typ = LogicalType :: decimal ( 10 , 2 ) ;
310
+ let typ = LogicalTypeHandle :: decimal ( 10 , 2 ) ;
311
311
312
312
assert_eq ! ( typ. id( ) , crate :: core:: LogicalTypeId :: Decimal ) ;
313
313
assert_eq ! ( typ. decimal_width( ) , 10 ) ;
@@ -316,7 +316,7 @@ mod test {
316
316
317
317
#[ test]
318
318
fn test_decimal_methods ( ) {
319
- let typ = LogicalType :: new ( crate :: core:: LogicalTypeId :: Varchar ) ;
319
+ let typ = LogicalTypeHandle :: from ( crate :: core:: LogicalTypeId :: Varchar ) ;
320
320
321
321
assert_eq ! ( typ. decimal_width( ) , 0 ) ;
322
322
assert_eq ! ( typ. decimal_scale( ) , 0 ) ;
@@ -325,10 +325,10 @@ mod test {
325
325
#[ test]
326
326
fn test_union_type ( ) {
327
327
let fields = & [
328
- ( "hello" , LogicalType :: new ( LogicalTypeId :: Boolean ) ) ,
329
- ( "world" , LogicalType :: new ( LogicalTypeId :: Integer ) ) ,
328
+ ( "hello" , LogicalTypeHandle :: from ( LogicalTypeId :: Boolean ) ) ,
329
+ ( "world" , LogicalTypeHandle :: from ( LogicalTypeId :: Integer ) ) ,
330
330
] ;
331
- let typ = LogicalType :: union_type ( fields) ;
331
+ let typ = LogicalTypeHandle :: union_type ( fields) ;
332
332
333
333
assert_eq ! ( typ. num_children( ) , 2 ) ;
334
334
0 commit comments