pub struct PubSub<T: Clone>(/* private fields */);Expand description
A pub/sub struct which allows many listeners to subscribe to many publishers, without leaking callbacks as listeners are dropped.
Unlike mpsc etc., PubSub has no internal queue and is completely
synchronous.
Implementations§
Source§impl<T: Clone + 'static> PubSub<T>
impl<T: Clone + 'static> PubSub<T>
Sourcepub fn callback(&self) -> Callback<T>
pub fn callback(&self) -> Callback<T>
Get this PubSub<_>’s .emit_all() method as a Callback<T>.
pub fn as_boxfn(&self) -> Box<dyn Fn(T) + Send + Sync + 'static>
Sourcepub async fn listen_once(&self) -> Result<T, Canceled>
pub async fn listen_once(&self) -> Result<T, Canceled>
Await this PubSub<_>’s next call to emit_all(), once.
Sourcepub fn subscriber(&self) -> Subscriber<T>
pub fn subscriber(&self) -> Subscriber<T>
Create a Subscriber from this PubSub, which is the reciprocal of
PubSub::callback (a struct which only allows sending), a struct which
only allows receiving via Subscriber::add_listener.
Trait Implementations§
Source§impl<T: Clone + 'static> AddListener<Callback<T>> for PubSub<T>
impl<T: Clone + 'static> AddListener<Callback<T>> for PubSub<T>
Source§fn add_listener(&self, f: Callback<T>) -> Subscription
fn add_listener(&self, f: Callback<T>) -> Subscription
Register a listener to this
PubSub<_>, which will be automatically
deregistered when the return Subscription is dropped. Read moreSource§impl<T, U> AddListener<U> for PubSub<T>
impl<T, U> AddListener<U> for PubSub<T>
Source§fn add_listener(&self, f: U) -> Subscription
fn add_listener(&self, f: U) -> Subscription
Register a listener to this
PubSub<_>, which will be automatically
deregistered when the return Subscription is dropped. Read moreimpl<T: Clone> Send for PubSub<T>
impl<T: Clone> Sync for PubSub<T>
Auto Trait Implementations§
impl<T> Freeze for PubSub<T>
impl<T> !RefUnwindSafe for PubSub<T>
impl<T> Unpin for PubSub<T>
impl<T> !UnwindSafe for PubSub<T>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
Convert
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
Convert
self to a value of a Properties struct.