pub struct ObserverMut<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> ObserverMut<E>
impl<E> ObserverMut<E>
Sourcepub fn new() -> ObserverMut<E>
pub fn new() -> ObserverMut<E>
Creates a new [ObserverMut with no active callbacks.
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.
Sourcepub fn callbacks(&self) -> Option<CallbacksMut<'_, E>>
pub fn callbacks(&self) -> Option<CallbacksMut<'_, 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.
Trait Implementations§
Source§impl<E> Debug for ObserverMut<E>where
E: Debug,
impl<E> Debug for ObserverMut<E>where
E: Debug,
Source§impl<E> Default for ObserverMut<E>
impl<E> Default for ObserverMut<E>
Source§fn default() -> ObserverMut<E>
fn default() -> ObserverMut<E>
impl<E> Send for ObserverMut<E>where
E: Send,
impl<E> Sync for ObserverMut<E>where
E: Sync,
Auto Trait Implementations§
impl<E> !Freeze for ObserverMut<E>
impl<E> !RefUnwindSafe for ObserverMut<E>
impl<E> !UnwindSafe for ObserverMut<E>
impl<E> Unpin for ObserverMut<E>
impl<E> UnsafeUnpin for ObserverMut<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
impl<T> ErasedDestructor for Twhere
T: 'static,
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 more