#[non_exhaustive]pub struct Subscriber<Handler> { /* private fields */ }Expand description
A subscriber that provides data through a Handler.
Subscribers can be created from a zenoh Session
with the declare_subscriber function.
Callback subscribers will run in background until the session is closed, or until it is undeclared. On the other hand, subscribers with a handler are automatically undeclared when dropped.
§Examples
Using callback:
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
session
.declare_subscriber("key/expression")
.callback(|sample| { println!("Received: {} {:?}", sample.key_expr(), sample.payload()) })
.await
.unwrap();
// subscriber run in background until the session is closedUsing channel handler:
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let subscriber = session
.declare_subscriber("key/expression")
.with(flume::bounded(32))
.await
.unwrap();
while let Ok(sample) = subscriber.recv_async().await {
println!("Received: {} {:?}", sample.key_expr(), sample.payload());
}
// subscriber is undeclared at the end of the scopeImplementations§
Source§impl<Handler> Subscriber<Handler>
impl<Handler> Subscriber<Handler>
Sourcepub fn id(&self) -> EntityGlobalId
Available on crate feature unstable only.
pub fn id(&self) -> EntityGlobalId
unstable only.Returns the EntityGlobalId of this Subscriber.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let subscriber = session.declare_subscriber("key/expression")
.await
.unwrap();
let subscriber_id = subscriber.id();Sourcepub fn handler(&self) -> &Handler
pub fn handler(&self) -> &Handler
Returns a reference to this subscriber’s handler.
An handler is anything that implements crate::handlers::IntoHandler.
The default handler is crate::handlers::DefaultHandler.
Sourcepub fn handler_mut(&mut self) -> &mut Handler
pub fn handler_mut(&mut self) -> &mut Handler
Returns a mutable reference to this subscriber’s handler.
An handler is anything that implements crate::handlers::IntoHandler.
The default handler is crate::handlers::DefaultHandler.
Sourcepub fn undeclare(self) -> SubscriberUndeclaration<Handler>where
Handler: Send,
pub fn undeclare(self) -> SubscriberUndeclaration<Handler>where
Handler: Send,
Undeclare the Subscriber.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let subscriber = session.declare_subscriber("key/expression")
.await
.unwrap();
subscriber.undeclare().await.unwrap();Trait Implementations§
Source§impl<Handler: Debug> Debug for Subscriber<Handler>
impl<Handler: Debug> Debug for Subscriber<Handler>
Source§impl<Handler> DerefMut for Subscriber<Handler>
impl<Handler> DerefMut for Subscriber<Handler>
Source§impl<Handler> Drop for Subscriber<Handler>
impl<Handler> Drop for Subscriber<Handler>
Auto Trait Implementations§
impl<Handler> Freeze for Subscriber<Handler>where
Handler: Freeze,
impl<Handler> !RefUnwindSafe for Subscriber<Handler>
impl<Handler> Send for Subscriber<Handler>where
Handler: Send,
impl<Handler> Sync for Subscriber<Handler>where
Handler: Sync,
impl<Handler> Unpin for Subscriber<Handler>where
Handler: Unpin,
impl<Handler> !UnwindSafe for Subscriber<Handler>
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, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
Access::load.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 more