diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 5e3af4644..e0b405014 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -383,14 +383,6 @@ typedef struct z_owned_closure_reply_t { * A data sample. * * A sample is the value associated to a given resource at a given point in time. - * - * Members: - * z_keyexpr_t keyexpr: The resource key of this data sample. - * z_bytes_t payload: The value of this data sample. - * z_encoding_t encoding: The encoding of the value of this data sample. - * z_sample_kind_t kind: The kind of this data sample (PUT or DELETE). - * z_timestamp_t timestamp: The timestamp of this data sample. - * z_attachment_t attachment: The attachment of this data sample. */ typedef struct z_sample_t { const void *_inner; @@ -2503,6 +2495,7 @@ ZENOHC_API void zc_sample_drop(struct zc_owned_sample_t *sample); * Calling this function using a dropped sample is undefined behaviour. */ ZENOHC_API struct z_sample_t zc_sample_loan(const struct zc_owned_sample_t *sample); +ZENOHC_API struct zc_owned_sample_t zc_sample_null(void); /** * Increments the session's reference count, returning a new owning handle. */ diff --git a/src/commons.rs b/src/commons.rs index 555a380be..d23618846 100644 --- a/src/commons.rs +++ b/src/commons.rs @@ -156,14 +156,6 @@ pub extern "C" fn z_qos_default() -> z_qos_t { /// A data sample. /// /// A sample is the value associated to a given resource at a given point in time. -/// -/// Members: -/// z_keyexpr_t keyexpr: The resource key of this data sample. -/// z_bytes_t payload: The value of this data sample. -/// z_encoding_t encoding: The encoding of the value of this data sample. -/// z_sample_kind_t kind: The kind of this data sample (PUT or DELETE). -/// z_timestamp_t timestamp: The timestamp of this data sample. -/// z_attachment_t attachment: The attachment of this data sample. #[repr(C)] pub struct z_sample_t<'a> { _inner: &'a (), @@ -177,9 +169,6 @@ impl<'a> core::ops::Deref for z_sample_t<'a> { impl<'a> z_sample_t<'a> { pub fn new(sample: &'a Sample) -> Self { - if !sample.value.payload.zslices().count() <= 1 { - panic!("Attempted to construct z_sample_t from discontiguous buffer, this is definitely a bug in zenoh-c, please report it.") - }; z_sample_t { _inner: unsafe { core::mem::transmute(sample) }, } @@ -285,6 +274,11 @@ pub extern "C" fn zc_sample_drop(sample: &mut zc_owned_sample_t) { core::mem::drop(sample.take()); } +#[no_mangle] +pub extern "C" fn zc_sample_null() -> zc_owned_sample_t { + None.into() +} + /// A :c:type:`z_encoding_t` integer `prefix`. /// /// - **Z_ENCODING_PREFIX_EMPTY** diff --git a/src/lib.rs b/src/lib.rs index 9c01e4aa2..2ff9259c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,6 +58,14 @@ trait GuardedTransmute { fn transmute(self) -> D; } +/// For internal use only. +/// +/// This macro is used to establish the equivalence between a Rust type (first parameter) and a C layout (second parameter). +/// +/// It automatically implements `From`, `Deref` and `DerefMut` to make writing code around these equivalent types. +/// +/// Because carrying around the proper semantics of lifetimes is hard, this macro fails to produce working code when lifetimes are +/// present in either parameter. You may then call it with the `noderefs` prefix to avoid the offending implementations being defined. #[macro_export] macro_rules! impl_guarded_transmute { ($src_type:ty, $dst_type:ty) => {