pub struct SubscriberBuilder<'a, 'b, Handler, const BACKGROUND: bool = false> { /* private fields */ }Expand description
A builder for initializing a Subscriber.
Returned by the
Session::declare_subscriber method.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let subscriber = session
.declare_subscriber("key/expression")
.await
.unwrap();Implementations§
Source§impl<'a, 'b> SubscriberBuilder<'a, 'b, DefaultHandler>
impl<'a, 'b> SubscriberBuilder<'a, 'b, DefaultHandler>
Sourcepub fn callback<F>(
self,
callback: F,
) -> SubscriberBuilder<'a, 'b, Callback<Sample>>
pub fn callback<F>( self, callback: F, ) -> SubscriberBuilder<'a, 'b, Callback<Sample>>
Receive the samples for this subscription with a callback.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let subscriber = session
.declare_subscriber("key/expression")
.callback(|sample| { println!("Received: {} {:?}", sample.key_expr(), sample.payload()); })
.await
.unwrap();Sourcepub fn callback_mut<F>(
self,
callback: F,
) -> SubscriberBuilder<'a, 'b, Callback<Sample>>
pub fn callback_mut<F>( self, callback: F, ) -> SubscriberBuilder<'a, 'b, Callback<Sample>>
Receive the samples for this subscription with a mutable callback.
Using this guarantees that your callback will never be called concurrently.
If your callback is also accepted by the callback method, we suggest you use it instead of callback_mut.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let mut n = 0;
let subscriber = session
.declare_subscriber("key/expression")
.callback_mut(move |_sample| { n += 1; })
.await
.unwrap();Sourcepub fn with<Handler>(
self,
handler: Handler,
) -> SubscriberBuilder<'a, 'b, Handler>where
Handler: IntoHandler<Sample>,
pub fn with<Handler>(
self,
handler: Handler,
) -> SubscriberBuilder<'a, 'b, Handler>where
Handler: IntoHandler<Sample>,
Receive the samples for this subscription with a Handler.
§Examples
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());
}Source§impl<'a, 'b> SubscriberBuilder<'a, 'b, Callback<Sample>>
impl<'a, 'b> SubscriberBuilder<'a, 'b, Callback<Sample>>
Sourcepub fn background(self) -> SubscriberBuilder<'a, 'b, Callback<Sample>, true>
pub fn background(self) -> SubscriberBuilder<'a, 'b, Callback<Sample>, true>
Make the subscriber run in the background until the session is closed.
The background builder doesn’t return a Subscriber object anymore.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
// no need to assign and keep a variable with a background subscriber
session
.declare_subscriber("key/expression")
.callback(|sample| { println!("Received: {} {:?}", sample.key_expr(), sample.payload()); })
.background()
.await
.unwrap();Source§impl<Handler, const BACKGROUND: bool> SubscriberBuilder<'_, '_, Handler, BACKGROUND>
impl<Handler, const BACKGROUND: bool> SubscriberBuilder<'_, '_, Handler, BACKGROUND>
Sourcepub fn allowed_origin(self, origin: Locality) -> Self
pub fn allowed_origin(self, origin: Locality) -> Self
Changes the Locality of received publications.
Restricts the matching publications that will be received by this Subscriber to the ones
that have the given Locality.
Trait Implementations§
Source§impl<'a, 'b, Handler: Debug, const BACKGROUND: bool> Debug for SubscriberBuilder<'a, 'b, Handler, BACKGROUND>
impl<'a, 'b, Handler: Debug, const BACKGROUND: bool> Debug for SubscriberBuilder<'a, 'b, Handler, BACKGROUND>
Source§impl IntoFuture for SubscriberBuilder<'_, '_, Callback<Sample>, true>
impl IntoFuture for SubscriberBuilder<'_, '_, Callback<Sample>, true>
Source§type Output = <SubscriberBuilder<'_, '_, Callback<Sample>, true> as Resolvable>::To
type Output = <SubscriberBuilder<'_, '_, Callback<Sample>, true> as Resolvable>::To
Source§type IntoFuture = Ready<<SubscriberBuilder<'_, '_, Callback<Sample>, true> as Resolvable>::To>
type IntoFuture = Ready<<SubscriberBuilder<'_, '_, Callback<Sample>, true> as Resolvable>::To>
Source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Source§impl<Handler> IntoFuture for SubscriberBuilder<'_, '_, Handler>
impl<Handler> IntoFuture for SubscriberBuilder<'_, '_, Handler>
Source§type Output = <SubscriberBuilder<'_, '_, Handler> as Resolvable>::To
type Output = <SubscriberBuilder<'_, '_, Handler> as Resolvable>::To
Source§type IntoFuture = Ready<<SubscriberBuilder<'_, '_, Handler> as Resolvable>::To>
type IntoFuture = Ready<<SubscriberBuilder<'_, '_, Handler> as Resolvable>::To>
Source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Source§impl Resolvable for SubscriberBuilder<'_, '_, Callback<Sample>, true>
impl Resolvable for SubscriberBuilder<'_, '_, Callback<Sample>, true>
Source§impl<Handler> Resolvable for SubscriberBuilder<'_, '_, Handler>
impl<Handler> Resolvable for SubscriberBuilder<'_, '_, Handler>
Source§impl Wait for SubscriberBuilder<'_, '_, Callback<Sample>, true>
impl Wait for SubscriberBuilder<'_, '_, Callback<Sample>, true>
Source§fn wait(self) -> <Self as Resolvable>::To
fn wait(self) -> <Self as Resolvable>::To
Source§impl<Handler> Wait for SubscriberBuilder<'_, '_, Handler>
impl<Handler> Wait for SubscriberBuilder<'_, '_, Handler>
Source§fn wait(self) -> <Self as Resolvable>::To
fn wait(self) -> <Self as Resolvable>::To
Auto Trait Implementations§
impl<'a, 'b, Handler, const BACKGROUND: bool> Freeze for SubscriberBuilder<'a, 'b, Handler, BACKGROUND>where
Handler: Freeze,
impl<'a, 'b, Handler, const BACKGROUND: bool = false> !RefUnwindSafe for SubscriberBuilder<'a, 'b, Handler, BACKGROUND>
impl<'a, 'b, Handler, const BACKGROUND: bool> Send for SubscriberBuilder<'a, 'b, Handler, BACKGROUND>where
Handler: Send,
impl<'a, 'b, Handler, const BACKGROUND: bool> Sync for SubscriberBuilder<'a, 'b, Handler, BACKGROUND>where
Handler: Sync,
impl<'a, 'b, Handler, const BACKGROUND: bool> Unpin for SubscriberBuilder<'a, 'b, Handler, BACKGROUND>where
Handler: Unpin,
impl<'a, 'b, Handler, const BACKGROUND: bool = false> !UnwindSafe for SubscriberBuilder<'a, 'b, Handler, BACKGROUND>
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 more