pub struct Subscribers<T: ?Sized + Send + Sync + 'static> { /* private fields */ }Expand description
A list of subscribers held as weak references.
This type is useful for implementing observer/listener patterns where:
- Subscribers register to receive notifications
- The registry doesn’t keep subscribers alive (weak references)
- Dead subscribers are cleaned up during registration
§Example
use std::sync::Arc;
use scion_stack::types::Subscribers;
trait EventReceiver: Send + Sync {
fn on_event(&self, data: &str);
}
struct MyReceiver;
impl EventReceiver for MyReceiver {
fn on_event(&self, data: &str) {
println!("Received: {}", data);
}
}
let subscribers: Subscribers<dyn EventReceiver> = Subscribers::new();
let receiver: Arc<dyn EventReceiver> = Arc::new(MyReceiver);
subscribers.register(receiver.clone());
subscribers.for_each(|r| r.on_event("hello"));
drop(receiver);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Subscribers<T>where
T: ?Sized,
impl<T> RefUnwindSafe for Subscribers<T>where
T: ?Sized,
impl<T> Send for Subscribers<T>where
T: ?Sized,
impl<T> Sync for Subscribers<T>where
T: ?Sized,
impl<T> Unpin for Subscribers<T>where
T: ?Sized,
impl<T> UnwindSafe for Subscribers<T>where
T: ?Sized,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request