#[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 closed
Using 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 scope
Implementations§
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
.
This subscriber’s crate::handlers::Callback
will be dropped as part of the
undeclaration.
§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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform
distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p
of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator
of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
random
to avoid conflict with the new gen
keyword in Rust 2024.Rng::random
.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
random_range
Rng::random_range
.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32
.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64
.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest
entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut
wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
RngCore
to a RngReadAdapter
.