diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 38ce877be..ccb121f66 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -2267,6 +2267,10 @@ ZENOHC_API void z_publisher_delete_options_default(struct z_publisher_delete_opt * Frees memory and resets publisher to its gravestone state. Also attempts undeclare publisher. */ ZENOHC_API void z_publisher_drop(struct z_owned_publisher_t *this_); +/** + * Returns the ID of the publisher. + */ +ZENOHC_API struct z_entity_global_id_t z_publisher_id(const struct z_loaned_publisher_t *publisher); /** * Returns the key expression of the publisher. */ diff --git a/src/publisher.rs b/src/publisher.rs index 2c674605b..bdedfdb09 100644 --- a/src/publisher.rs +++ b/src/publisher.rs @@ -16,10 +16,12 @@ use crate::errors; use crate::transmute::unwrap_ref_unchecked; use crate::transmute::unwrap_ref_unchecked_mut; 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::z_entity_global_id_t; use crate::z_owned_encoding_t; use crate::z_owned_source_info_t; use crate::z_timestamp_t; @@ -270,6 +272,13 @@ pub extern "C" fn z_publisher_delete( } } +/// Returns the ID of the publisher. +#[no_mangle] +pub extern "C" fn z_publisher_id(publisher: &z_loaned_publisher_t) -> z_entity_global_id_t { + let publisher = publisher.transmute_ref(); + publisher.id().transmute_copy() +} + /// Returns the key expression of the publisher. #[no_mangle] pub extern "C" fn z_publisher_keyexpr(publisher: &z_loaned_publisher_t) -> &z_loaned_keyexpr_t {