diff --git a/zenoh/src/publication.rs b/zenoh/src/publication.rs index e0cd1d33c6..d54a77b793 100644 --- a/zenoh/src/publication.rs +++ b/zenoh/src/publication.rs @@ -318,25 +318,6 @@ impl<'a> Publisher<'a> { } } - /// Send data with [`kind`](SampleKind) (Put or Delete). - /// - /// # Examples - /// ``` - /// # async_std::task::block_on(async { - /// use zenoh::prelude::r#async::*; - /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); - /// publisher.write(SampleKind::Put, "value").res().await.unwrap(); - /// # }) - /// ``` - pub fn write(&self, kind: SampleKind, value: IntoValue) -> Publication - where - IntoValue: Into, - { - self._write(kind, value.into()) - } - /// Put data. /// /// # Examples @@ -448,6 +429,43 @@ impl<'a> Publisher<'a> { } } +/// Internal function for sending data with specified [`kind`](SampleKind) +pub trait HasWriteWithSampleKind { + type WriteOutput<'a> + where + Self: 'a; + fn write>( + &self, + kind: SampleKind, + value: IntoValue, + ) -> Self::WriteOutput<'_>; +} + +impl<'a> HasWriteWithSampleKind for Publisher<'a> { + type WriteOutput<'b> = Publication<'b> + where + 'a: 'b; + /// Send data with [`kind`](SampleKind) (Put or Delete). + /// + /// # Examples + /// ``` + /// # async_std::task::block_on(async { + /// use zenoh::prelude::r#async::*; + /// use zenoh::publication::HasWriteWithSampleKind; + /// + /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); + /// publisher.write(SampleKind::Put, "value").res().await.unwrap(); + /// # }) + /// ``` + fn write(&self, kind: SampleKind, value: IntoValue) -> Self::WriteOutput<'_> + where + IntoValue: Into, + { + self._write(kind, value.into()) + } +} + /// Functions to create zenoh entities with `'static` lifetime. /// /// This trait contains functions to create zenoh entities like @@ -1351,6 +1369,7 @@ mod tests { #[test] fn sample_kind_integrity_in_publication() { + use crate::publication::HasWriteWithSampleKind; use crate::{open, prelude::sync::*}; use zenoh_protocol::core::SampleKind;