diff --git a/src/commons.rs b/src/commons.rs index c27e1eef9..2bd44b978 100644 --- a/src/commons.rs +++ b/src/commons.rs @@ -20,12 +20,8 @@ use std::str::from_utf8; use std::str::FromStr; use crate::errors; -use crate::transmute::Inplace; use crate::transmute::TransmuteCopy; -use crate::transmute::TransmuteFromHandle; use crate::transmute::TransmuteIntoHandle; -use crate::transmute::TransmuteRef; -use crate::transmute::TransmuteUninitPtr; use crate::transmute2::CTypeRef; use crate::transmute2::IntoCType; use crate::transmute2::LoanedCTypeRef; @@ -168,7 +164,7 @@ pub extern "C" fn z_sample_attachment(this: &z_loaned_sample_t) -> *const z_loan /// Returns the sample source_info. #[no_mangle] pub extern "C" fn z_sample_source_info(this: &z_loaned_sample_t) -> &z_loaned_source_info_t { - this.as_rust_type_ref().source_info().transmute_handle() + this.as_rust_type_ref().source_info().as_loaned_ctype_ref() } /// Constructs an owned shallow copy of the sample (i.e. all modficiations applied to the copy, might be visible in the original) in provided uninitilized memory location. @@ -589,32 +585,32 @@ pub extern "C" fn z_entity_global_id_eid(this: &z_entity_global_id_t) -> u32 { this.as_rust_type_ref().eid() } pub use crate::opaque_types::z_loaned_source_info_t; -decl_transmute_handle!(SourceInfo, z_loaned_source_info_t); pub use crate::opaque_types::z_owned_source_info_t; -decl_transmute_owned!(SourceInfo, z_owned_source_info_t); - -validate_equivalence!(z_owned_source_info_t, z_loaned_source_info_t); +decl_c_type!( + owned(z_owned_source_info_t, SourceInfo), + loaned(z_loaned_source_info_t, SourceInfo) +); /// Create source info #[no_mangle] pub extern "C" fn z_source_info_new( - this: *mut MaybeUninit, + this: &mut MaybeUninit, source_id: &z_entity_global_id_t, source_sn: u64, ) -> errors::z_error_t { - let this = this.transmute_uninit_ptr(); + let this = this.as_rust_type_mut_uninit(); let source_info = SourceInfo { source_id: Some(*source_id.as_rust_type_ref()), source_sn: Some(source_sn), }; - Inplace::init(this, source_info); + this.write(source_info); errors::Z_OK } /// Returns the source_id of the source info. #[no_mangle] pub extern "C" fn z_source_info_id(this: &z_loaned_source_info_t) -> z_entity_global_id_t { - match this.transmute_ref().source_id { + match this.as_rust_type_ref().source_id { Some(source_id) => source_id, None => EntityGlobalId::default(), } @@ -624,29 +620,29 @@ pub extern "C" fn z_source_info_id(this: &z_loaned_source_info_t) -> z_entity_gl /// Returns the source_sn of the source info. #[no_mangle] pub extern "C" fn z_source_info_sn(this: &z_loaned_source_info_t) -> u64 { - this.transmute_ref().source_sn.unwrap_or(0) + this.as_rust_type_ref().source_sn.unwrap_or(0) } /// Returns ``true`` if source info is valid, ``false`` if it is in gravestone state. #[no_mangle] pub extern "C" fn z_source_info_check(this: &z_owned_source_info_t) -> bool { - this.transmute_ref().source_id.is_some() || this.transmute_ref().source_sn.is_some() + this.as_rust_type_ref().source_id.is_some() || this.as_rust_type_ref().source_sn.is_some() } /// Borrows source info. #[no_mangle] pub extern "C" fn z_source_info_loan(this: &z_owned_source_info_t) -> &z_loaned_source_info_t { - this.transmute_ref().transmute_handle() + this.as_rust_type_ref().as_loaned_ctype_ref() } /// Frees the memory and invalidates the source info, resetting it to a gravestone state. #[no_mangle] pub extern "C" fn z_source_info_drop(this: &mut z_owned_source_info_t) { - Inplace::drop(this.transmute_mut()); + *this.as_rust_type_mut() = SourceInfo::default(); } /// Constructs source info in its gravestone state. #[no_mangle] -pub extern "C" fn z_source_info_null(this: *mut MaybeUninit) { - Inplace::empty(this.transmute_uninit_ptr()); +pub extern "C" fn z_source_info_null(this: &mut MaybeUninit) { + this.as_rust_type_mut_uninit().write(SourceInfo::default()); } diff --git a/src/get.rs b/src/get.rs index 47ce6b7ac..ee8fcf840 100644 --- a/src/get.rs +++ b/src/get.rs @@ -272,7 +272,7 @@ pub unsafe extern "C" fn z_get( get = get.encoding(encoding); } if let Some(source_info) = unsafe { options.source_info.as_mut() } { - let source_info = source_info.transmute_mut().extract(); + let source_info = std::mem::take(source_info.as_rust_type_mut()); get = get.source_info(source_info); } if let Some(attachment) = unsafe { options.attachment.as_mut() } { diff --git a/src/publisher.rs b/src/publisher.rs index 5f800fa69..80a9af433 100644 --- a/src/publisher.rs +++ b/src/publisher.rs @@ -207,7 +207,7 @@ pub unsafe extern "C" fn z_publisher_put( put = put.encoding(encoding); }; if let Some(source_info) = unsafe { options.source_info.as_mut() } { - let source_info = source_info.transmute_mut().extract(); + let source_info = std::mem::take(source_info.as_rust_type_mut()); put = put.source_info(source_info); }; if let Some(attachment) = unsafe { options.attachment.as_mut() } { diff --git a/src/put.rs b/src/put.rs index 2955766cc..f444c008b 100644 --- a/src/put.rs +++ b/src/put.rs @@ -1,3 +1,4 @@ +use std::mem::take; use std::ptr::null_mut; // @@ -96,7 +97,7 @@ pub extern "C" fn z_put( put = put.encoding(encoding); }; if let Some(source_info) = unsafe { options.source_info.as_mut() } { - let source_info = source_info.transmute_mut().extract(); + let source_info = std::mem::take(source_info.as_rust_type_mut()); put = put.source_info(source_info); }; if let Some(attachment) = unsafe { options.attachment.as_mut() } { diff --git a/src/queryable.rs b/src/queryable.rs index 56594d72e..0a64eda66 100644 --- a/src/queryable.rs +++ b/src/queryable.rs @@ -301,7 +301,7 @@ pub extern "C" fn z_query_reply( reply = reply.encoding(encoding); }; if let Some(source_info) = unsafe { options.source_info.as_mut() } { - let source_info = source_info.transmute_mut().extract(); + let source_info = std::mem::take(source_info.as_rust_type_mut()); reply = reply.source_info(source_info); }; if let Some(attachment) = unsafe { options.attachment.as_mut() } { @@ -390,7 +390,7 @@ pub unsafe extern "C" fn z_query_reply_del( let mut reply = query.reply_del(key_expr); if let Some(options) = options { if let Some(source_info) = unsafe { options.source_info.as_mut() } { - let source_info = source_info.transmute_mut().extract(); + let source_info = std::mem::take(source_info.as_rust_type_mut()); reply = reply.source_info(source_info); }; if let Some(attachment) = unsafe { options.attachment.as_mut() } { diff --git a/src/querying_subscriber.rs b/src/querying_subscriber.rs index 2abe1dde2..848f6a8f2 100644 --- a/src/querying_subscriber.rs +++ b/src/querying_subscriber.rs @@ -199,7 +199,7 @@ pub unsafe extern "C" fn ze_querying_subscriber_get( get = get.encoding(encoding); } if let Some(source_info) = unsafe { options.source_info.as_mut() } { - let source_info = source_info.transmute_mut().extract(); + let source_info = std::mem::take(source_info.as_rust_type_mut()); get = get.source_info(source_info); } if let Some(attachment) = unsafe { options.attachment.as_mut() } {