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. Explicitly does not implement clone, as this is intended as
RAII, even though the internal data structures are Clone because they
need to be sent to listeners.
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>.
Sourcepub fn add_notify_listener(&self, cb: &Callback<()>) -> Subscription
pub fn add_notify_listener(&self, cb: &Callback<()>) -> Subscription
Subscribe a Callback<()> that fires whenever this PubSub emits,
discarding the emitted value. Useful when the subscriber only
needs a “something changed” notification.
Sourcepub fn as_boxfn(&self) -> Box<dyn Fn(T) + 'static>
pub fn as_boxfn(&self) -> Box<dyn Fn(T) + 'static>
Convert PubSub::emit to a Box<dyn Fn(T)>.
Sourcepub async fn read_next(&self) -> Result<T, Canceled>
pub async fn read_next(&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
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
PubSub<_>, which will be automatically
deregistered when the return Subscription is dropped. Read moreAuto Trait Implementations§
impl<T> Freeze for PubSub<T>
impl<T> !RefUnwindSafe for PubSub<T>
impl<T> !Send for PubSub<T>
impl<T> !Sync for PubSub<T>
impl<T> Unpin for PubSub<T>
impl<T> UnsafeUnpin for PubSub<T>
impl<T> !UnwindSafe for PubSub<T>
Blanket Implementations§
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> 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>
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
self to a value of a Properties struct.