Struct Observer
pub struct Observer<F> { /* private fields */ }Expand description
Data structure used to handle publish/subscribe callbacks of specific type. Observers perform subscriber changes in thread-safe manner, using atomic hardware intrinsics.
Implementations§
§impl<F> Observer<F>where
F: 'static,
impl<F> Observer<F>where
F: 'static,
pub fn has_subscribers(&self) -> bool
pub fn clean(&self)
pub fn clean(&self)
Cleanup already released subscriptions. Whenever a Subscription is dropped, the callback is released. However, the weak reference to callback may still be kept around until it becomes touched by operations such as Observer::subscribe or [Observer::callbacks].
This method allows to perform stale callback cleanup without waiting for callbacks to be visited.
pub fn unsubscribe(&self, id: &Origin) -> bool
pub fn trigger<E>(&self, each: E)
pub fn trigger<E>(&self, each: E)
Returns a snapshot of callbacks subscribed to this observer at the moment when this method has been called. This snapshot can be iterated over to get access to individual callbacks and trigger them.
pub fn subscribe_with(&self, id: Origin, callback: F)
pub fn subscribe_with(&self, id: Origin, callback: F)
Subscribes a callback parameter to a current Observer.
Returns a subscription object which - when dropped - will unsubscribe current callback.
If the id was already present in the observer, current callback will be ignored.
Trait Implementations§
Auto Trait Implementations§
impl<F> !Freeze for Observer<F>
impl<F> RefUnwindSafe for Observer<F>where
F: RefUnwindSafe,
impl<F> Send for Observer<F>
impl<F> Sync for Observer<F>
impl<F> Unpin for Observer<F>
impl<F> UnwindSafe for Observer<F>where
F: RefUnwindSafe,
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
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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