pub struct Observer<E> { /* 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§
source§impl<E> Observer<E>
impl<E> Observer<E>
pub fn has_subscribers(&self) -> bool
sourcepub 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.
sourcepub fn subscribe<F>(&self, callback: F) -> Subscription
pub fn subscribe<F>(&self, callback: F) -> Subscription
Subscribes a callback parameter to a current Observer. Returns a subscription object which - when dropped - will unsubscribe current callback.
Trait Implementations§
impl<E: Send> Send for Observer<E>
impl<E: Sync> Sync for Observer<E>
Auto Trait Implementations§
impl<E> !Freeze for Observer<E>
impl<E> !RefUnwindSafe for Observer<E>
impl<E> Unpin for Observer<E>
impl<E> !UnwindSafe for Observer<E>
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
Mutably borrows from an owned value. Read more