@@ -110,11 +110,11 @@ impl From<u32> for LogicalTypeId {
110110
111111/// DuckDB Logical Type.
112112/// <https://duckdb.org/docs/sql/data_types/overview>
113- pub struct LogicalType {
113+ pub struct LogicalTypeHandle {
114114 pub ( crate ) ptr : duckdb_logical_type ,
115115}
116116
117- impl Debug for LogicalType {
117+ impl Debug for LogicalTypeHandle {
118118 /// Debug implementation for LogicalType
119119 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
120120 let id = self . id ( ) ;
@@ -134,7 +134,7 @@ impl Debug for LogicalType {
134134 }
135135}
136136
137- impl Drop for LogicalType {
137+ impl Drop for LogicalTypeHandle {
138138 /// Drop implementation for LogicalType
139139 fn drop ( & mut self ) {
140140 if !self . ptr . is_null ( ) {
@@ -147,25 +147,25 @@ impl Drop for LogicalType {
147147 }
148148}
149149
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 {
160153 unsafe {
161154 Self {
162155 ptr : duckdb_create_logical_type ( id as u32 ) ,
163156 }
164157 }
165158 }
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+ }
166166
167167 /// 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 {
169169 unsafe {
170170 Self {
171171 ptr : duckdb_create_map_type ( key. ptr , value. ptr ) ,
@@ -174,7 +174,7 @@ impl LogicalType {
174174 }
175175
176176 /// Creates a list type from its child type.
177- pub fn list ( child_type : & LogicalType ) -> Self {
177+ pub fn list ( child_type : & LogicalTypeHandle ) -> Self {
178178 unsafe {
179179 Self {
180180 ptr : duckdb_create_list_type ( child_type. ptr ) ,
@@ -183,7 +183,7 @@ impl LogicalType {
183183 }
184184
185185 /// 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 {
187187 unsafe {
188188 Self {
189189 ptr : duckdb_create_array_type ( child_type. ptr , array_size) ,
@@ -213,7 +213,7 @@ impl LogicalType {
213213 }
214214
215215 /// Make a `LogicalType` for `struct`
216- pub fn struct_type ( fields : & [ ( & str , LogicalType ) ] ) -> Self {
216+ pub fn struct_type ( fields : & [ ( & str , LogicalTypeHandle ) ] ) -> Self {
217217 let keys: Vec < CString > = fields. iter ( ) . map ( |f| CString :: new ( f. 0 ) . unwrap ( ) ) . collect ( ) ;
218218 let values: Vec < duckdb_logical_type > = fields. iter ( ) . map ( |it| it. 1 . ptr ) . collect ( ) ;
219219 let name_ptrs = keys. iter ( ) . map ( |it| it. as_ptr ( ) ) . collect :: < Vec < * const c_char > > ( ) ;
@@ -230,7 +230,7 @@ impl LogicalType {
230230 }
231231
232232 /// Make a `LogicalType` for `union`
233- pub fn union_type ( fields : & [ ( & str , LogicalType ) ] ) -> Self {
233+ pub fn union_type ( fields : & [ ( & str , LogicalTypeHandle ) ] ) -> Self {
234234 let keys: Vec < CString > = fields. iter ( ) . map ( |f| CString :: new ( f. 0 ) . unwrap ( ) ) . collect ( ) ;
235235 let values: Vec < duckdb_logical_type > = fields. iter ( ) . map ( |it| it. 1 . ptr ) . collect ( ) ;
236236 let name_ptrs = keys. iter ( ) . map ( |it| it. as_ptr ( ) ) . collect :: < Vec < * const c_char > > ( ) ;
@@ -287,18 +287,18 @@ impl LogicalType {
287287 _ => panic ! ( "not a struct or union" ) ,
288288 }
289289 } ;
290- Self :: from ( c_logical_type)
290+ unsafe { Self :: new ( c_logical_type) }
291291 }
292292}
293293
294294#[ cfg( test) ]
295295mod test {
296- use crate :: core:: { LogicalType , LogicalTypeId } ;
296+ use crate :: core:: { LogicalTypeHandle , LogicalTypeId } ;
297297
298298 #[ test]
299299 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) ;
302302
303303 assert_eq ! ( typ. num_children( ) , 1 ) ;
304304 assert_eq ! ( typ. child_name( 0 ) , "hello" ) ;
@@ -307,7 +307,7 @@ mod test {
307307
308308 #[ test]
309309 fn test_decimal ( ) {
310- let typ = LogicalType :: decimal ( 10 , 2 ) ;
310+ let typ = LogicalTypeHandle :: decimal ( 10 , 2 ) ;
311311
312312 assert_eq ! ( typ. id( ) , crate :: core:: LogicalTypeId :: Decimal ) ;
313313 assert_eq ! ( typ. decimal_width( ) , 10 ) ;
@@ -316,7 +316,7 @@ mod test {
316316
317317 #[ test]
318318 fn test_decimal_methods ( ) {
319- let typ = LogicalType :: new ( crate :: core:: LogicalTypeId :: Varchar ) ;
319+ let typ = LogicalTypeHandle :: from ( crate :: core:: LogicalTypeId :: Varchar ) ;
320320
321321 assert_eq ! ( typ. decimal_width( ) , 0 ) ;
322322 assert_eq ! ( typ. decimal_scale( ) , 0 ) ;
@@ -325,10 +325,10 @@ mod test {
325325 #[ test]
326326 fn test_union_type ( ) {
327327 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 ) ) ,
330330 ] ;
331- let typ = LogicalType :: union_type ( fields) ;
331+ let typ = LogicalTypeHandle :: union_type ( fields) ;
332332
333333 assert_eq ! ( typ. num_children( ) , 2 ) ;
334334
0 commit comments