@@ -8,12 +8,12 @@ use serde_json::value::RawValue;
88use crate :: blocking:: block_on;
99use crate :: error:: { self , marshal_result, CosmosError , CosmosErrorCode } ;
1010use crate :: string:: { parse_cstr, safe_cstring_into_raw} ;
11- use crate :: ContainerClientHandle ;
1211
12+ /// Releases the memory associated with a [`ContainerClient`].
1313#[ no_mangle]
14- pub extern "C" fn cosmos_container_free ( container : * mut ContainerClientHandle ) {
14+ pub extern "C" fn cosmos_container_free ( container : * mut ContainerClient ) {
1515 if !container. is_null ( ) {
16- unsafe { ContainerClientHandle :: free_ptr ( container) }
16+ unsafe { drop ( Box :: from_raw ( container) ) }
1717 }
1818}
1919
@@ -39,7 +39,7 @@ fn create_item_inner(
3939/// * `out_error` - Output parameter that will receive error information if the function fails.
4040#[ no_mangle]
4141pub extern "C" fn cosmos_container_create_item (
42- container : * const ContainerClientHandle ,
42+ container : * const ContainerClient ,
4343 partition_key : * const c_char ,
4444 json_data : * const c_char ,
4545 out_error : * mut CosmosError ,
@@ -49,7 +49,7 @@ pub extern "C" fn cosmos_container_create_item(
4949 return CosmosErrorCode :: InvalidArgument ;
5050 }
5151
52- let container_handle = unsafe { ContainerClientHandle :: unwrap_ptr ( container) } ;
52+ let container_handle = unsafe { & * container } ;
5353
5454 let partition_key_str = match parse_cstr ( partition_key, error:: CSTR_INVALID_PARTITION_KEY ) {
5555 Ok ( s) => s,
@@ -87,7 +87,6 @@ fn upsert_item_inner(
8787) -> Result < ( ) , CosmosError > {
8888 let raw_value: Box < RawValue > = serde_json:: from_str ( json_str) ?;
8989 let pk = partition_key. to_string ( ) ;
90- tracing:: trace!( raw_value = %raw_value. get( ) , pk = %pk, "Upserting item" ) ;
9190 block_on ( container. upsert_item ( pk, raw_value, None ) ) ?;
9291 Ok ( ( ) )
9392}
@@ -101,7 +100,7 @@ fn upsert_item_inner(
101100/// * `out_error` - Output parameter that will receive error information if the function fails.
102101#[ no_mangle]
103102pub extern "C" fn cosmos_container_upsert_item (
104- container : * const ContainerClientHandle ,
103+ container : * const ContainerClient ,
105104 partition_key : * const c_char ,
106105 json_data : * const c_char ,
107106 out_error : * mut CosmosError ,
@@ -111,7 +110,7 @@ pub extern "C" fn cosmos_container_upsert_item(
111110 return CosmosErrorCode :: InvalidArgument ;
112111 }
113112
114- let container_handle = unsafe { ContainerClientHandle :: unwrap_ptr ( container) } ;
113+ let container_handle = unsafe { & * container } ;
115114
116115 let partition_key_str = match parse_cstr ( partition_key, error:: CSTR_INVALID_PARTITION_KEY ) {
117116 Ok ( s) => s,
@@ -165,7 +164,7 @@ fn read_item_inner(
165164/// * `out_error` - Output parameter that will receive error information if the function fails.
166165#[ no_mangle]
167166pub extern "C" fn cosmos_container_read_item (
168- container : * const ContainerClientHandle ,
167+ container : * const ContainerClient ,
169168 partition_key : * const c_char ,
170169 item_id : * const c_char ,
171170 out_json : * mut * mut c_char ,
@@ -180,7 +179,7 @@ pub extern "C" fn cosmos_container_read_item(
180179 return CosmosErrorCode :: InvalidArgument ;
181180 }
182181
183- let container_handle = unsafe { ContainerClientHandle :: unwrap_ptr ( container) } ;
182+ let container_handle = unsafe { & * container } ;
184183
185184 let partition_key_str = match parse_cstr ( partition_key, error:: CSTR_INVALID_PARTITION_KEY ) {
186185 Ok ( s) => s,
@@ -235,7 +234,7 @@ fn replace_item_inner(
235234/// * `out_error` - Output parameter that will receive error information if the function fails
236235#[ no_mangle]
237236pub extern "C" fn cosmos_container_replace_item (
238- container : * const ContainerClientHandle ,
237+ container : * const ContainerClient ,
239238 partition_key : * const c_char ,
240239 item_id : * const c_char ,
241240 json_data : * const c_char ,
@@ -250,7 +249,7 @@ pub extern "C" fn cosmos_container_replace_item(
250249 return CosmosErrorCode :: InvalidArgument ;
251250 }
252251
253- let container_handle = unsafe { ContainerClientHandle :: unwrap_ptr ( container) } ;
252+ let container_handle = unsafe { & * container } ;
254253
255254 let partition_key_str = match parse_cstr ( partition_key, error:: CSTR_INVALID_PARTITION_KEY ) {
256255 Ok ( s) => s,
@@ -311,7 +310,7 @@ fn delete_item_inner(
311310/// * `out_error` - Output parameter that will receive error information if the function fails
312311#[ no_mangle]
313312pub extern "C" fn cosmos_container_delete_item (
314- container : * const ContainerClientHandle ,
313+ container : * const ContainerClient ,
315314 partition_key : * const c_char ,
316315 item_id : * const c_char ,
317316 out_error : * mut CosmosError ,
@@ -320,7 +319,7 @@ pub extern "C" fn cosmos_container_delete_item(
320319 return CosmosErrorCode :: InvalidArgument ;
321320 }
322321
323- let container_handle = unsafe { ContainerClientHandle :: unwrap_ptr ( container) } ;
322+ let container_handle = unsafe { & * container } ;
324323
325324 let partition_key_str = match parse_cstr ( partition_key, error:: CSTR_INVALID_PARTITION_KEY ) {
326325 Ok ( s) => s,
@@ -366,15 +365,15 @@ fn read_container_inner(container: &ContainerClient) -> Result<String, CosmosErr
366365/// * `out_error` - Output parameter that will receive error information if the function fails.
367366#[ no_mangle]
368367pub extern "C" fn cosmos_container_read (
369- container : * const ContainerClientHandle ,
368+ container : * const ContainerClient ,
370369 out_json : * mut * mut c_char ,
371370 out_error : * mut CosmosError ,
372371) -> CosmosErrorCode {
373372 if container. is_null ( ) || out_json. is_null ( ) || out_error. is_null ( ) {
374373 return CosmosErrorCode :: InvalidArgument ;
375374 }
376375
377- let container_handle = unsafe { ContainerClientHandle :: unwrap_ptr ( container) } ;
376+ let container_handle = unsafe { & * container } ;
378377
379378 marshal_result (
380379 read_container_inner ( container_handle) ,
@@ -417,7 +416,7 @@ fn query_items_inner(
417416/// * `out_error` - Output parameter that will receive error information if the function fails.
418417#[ no_mangle]
419418pub extern "C" fn cosmos_container_query_items (
420- container : * const ContainerClientHandle ,
419+ container : * const ContainerClient ,
421420 query : * const c_char ,
422421 partition_key : * const c_char ,
423422 out_json : * mut * mut c_char ,
@@ -427,7 +426,7 @@ pub extern "C" fn cosmos_container_query_items(
427426 return CosmosErrorCode :: InvalidArgument ;
428427 }
429428
430- let container_handle = unsafe { ContainerClientHandle :: unwrap_ptr ( container) } ;
429+ let container_handle = unsafe { & * container } ;
431430
432431 let query_str = match parse_cstr ( query, error:: CSTR_INVALID_QUERY ) {
433432 Ok ( s) => s,
0 commit comments