pub struct Publisher<'a> { /* private fields */ }Expand description
A publisher that allows sending data through a stream.
Publishers are automatically undeclared when dropped.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let publisher = session.declare_publisher("key/expression").await.unwrap();
publisher.put("value").await.unwrap();Publisher implements the Sink trait which is useful for forwarding
streams to zenoh.
use futures::StreamExt;
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let mut subscriber = session.declare_subscriber("key/expression").await.unwrap();
let publisher = session.declare_publisher("another/key/expression").await.unwrap();
subscriber.stream().map(Ok).forward(publisher).await.unwrap();Implementations§
Source§impl<'a> Publisher<'a>
impl<'a> Publisher<'a>
Sourcepub fn id(&self) -> EntityGlobalId
Available on crate feature unstable only.
pub fn id(&self) -> EntityGlobalId
unstable only.Returns the EntityGlobalId of this Publisher.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let publisher = session.declare_publisher("key/expression")
.await
.unwrap();
let publisher_id = publisher.id();Sourcepub fn congestion_control(&self) -> CongestionControl
pub fn congestion_control(&self) -> CongestionControl
Get the CongestionControl applied when routing the data.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let publisher = session.declare_publisher("key/expression")
.await
.unwrap();
let congestion_control = publisher.congestion_control();Sourcepub fn reliability(&self) -> Reliability
Available on crate feature unstable only.
pub fn reliability(&self) -> Reliability
unstable only.Get the Reliability applied when routing the data.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let publisher = session.declare_publisher("key/expression")
.await
.unwrap();
let reliability = publisher.reliability();Sourcepub fn put<IntoZBytes>(&self, payload: IntoZBytes) -> PublisherPutBuilder<'_>
pub fn put<IntoZBytes>(&self, payload: IntoZBytes) -> PublisherPutBuilder<'_>
Publish the data. The subscribers matching the Publisher’s key expression will receive the
Sample with kind SampleKind::Put.
The builder allows customizing the publication: add the timestamp, attachment, etc. Some fields are pre-filled with the Publisher’s configuration and can be overridden.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let publisher = session.declare_publisher("key/expression").await.unwrap();
publisher.put("value").await.unwrap();Sourcepub fn delete(&self) -> PublisherDeleteBuilder<'_>
pub fn delete(&self) -> PublisherDeleteBuilder<'_>
Declare that the data associated with the Publisher’s key expression is deleted.
The subscribers will receive the Sample with
kind SampleKind::Delete.
The builder allows customizing the publication: add the timestamp, attachment, etc.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let publisher = session.declare_publisher("key/expression").await.unwrap();
publisher.delete().await.unwrap();Sourcepub fn matching_status(&self) -> impl Resolve<ZResult<MatchingStatus>> + '_
pub fn matching_status(&self) -> impl Resolve<ZResult<MatchingStatus>> + '_
Return the MatchingStatus of the publisher.
MatchingStatus::matching will return true if there exist Subscribers
matching the Publisher’s key expression and false otherwise.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let publisher = session.declare_publisher("key/expression").await.unwrap();
let matching_subscribers: bool = publisher
.matching_status()
.await
.unwrap()
.matching();Sourcepub fn matching_listener(&self) -> MatchingListenerBuilder<'_, DefaultHandler>
pub fn matching_listener(&self) -> MatchingListenerBuilder<'_, DefaultHandler>
Return a MatchingListener for this Publisher.
The MatchingListener will send a notification each time the MatchingStatus of
the Publisher changes.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let publisher = session.declare_publisher("key/expression").await.unwrap();
let matching_listener = publisher.matching_listener().await.unwrap();
while let Ok(matching_status) = matching_listener.recv_async().await {
if matching_status.matching() {
println!("Publisher has matching subscribers.");
} else {
println!("Publisher has NO MORE matching subscribers.");
}
}Sourcepub fn undeclare(self) -> impl Resolve<ZResult<()>> + 'a
pub fn undeclare(self) -> impl Resolve<ZResult<()>> + 'a
Undeclare the Publisher, informing the network that it needn’t optimize publications for its key expression anymore.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let publisher = session.declare_publisher("key/expression").await.unwrap();
publisher.undeclare().await.unwrap();Trait Implementations§
Source§impl Sink<Sample> for Publisher<'_>
impl Sink<Sample> for Publisher<'_>
Source§type Error = Box<dyn Error + Send + Sync>
type Error = Box<dyn Error + Send + Sync>
Source§fn poll_ready(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Sink to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: Sample) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: Sample) -> Result<(), Self::Error>
poll_ready which returned Poll::Ready(Ok(())). Read moreAuto Trait Implementations§
impl<'a> Freeze for Publisher<'a>
impl<'a> !RefUnwindSafe for Publisher<'a>
impl<'a> Send for Publisher<'a>
impl<'a> Sync for Publisher<'a>
impl<'a> Unpin for Publisher<'a>
impl<'a> !UnwindSafe for Publisher<'a>
Blanket Implementations§
Source§impl<Source> AccessAs for Source
impl<Source> AccessAs for Source
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T, Item> SinkExt<Item> for T
impl<T, Item> SinkExt<Item> for T
Source§fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
Source§fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
Source§fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
Source§fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
Into trait. Read moreSource§fn buffer(self, capacity: usize) -> Buffer<Self, Item>where
Self: Sized,
fn buffer(self, capacity: usize) -> Buffer<Self, Item>where
Self: Sized,
alloc only.Source§fn flush(&mut self) -> Flush<'_, Self, Item>where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self, Item>where
Self: Unpin,
Source§fn send(&mut self, item: Item) -> Send<'_, Self, Item>where
Self: Unpin,
fn send(&mut self, item: Item) -> Send<'_, Self, Item>where
Self: Unpin,
Source§fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>where
Self: Unpin,
fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>where
Self: Unpin,
Source§fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>
fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>
Source§fn right_sink<Si1>(self) -> Either<Si1, Self>
fn right_sink<Si1>(self) -> Either<Si1, Self>
Source§fn poll_ready_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>where
Self: Unpin,
fn poll_ready_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>where
Self: Unpin,
Sink::poll_ready on Unpin
sink types.Source§fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>where
Self: Unpin,
fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>where
Self: Unpin,
Sink::start_send on Unpin
sink types.