pub trait EventSource: 'static {
type Origin: Clone + 'static;
type Event: Send + 'static;
// Required method
fn subscribe(
&self,
origin: Self::Origin,
callback: Arc<dyn Fn(Self::Event) + Send + Sync + 'static>,
) -> SubscriptionHandle;
}Expand description
An external source of events that widgets can subscribe to.
Implementations include backend message buses, database change notifiers, file watchers, network response channels — any source that publishes events asynchronously and that widgets need to react to.
Required Associated Types§
Required Methods§
Sourcefn subscribe(
&self,
origin: Self::Origin,
callback: Arc<dyn Fn(Self::Event) + Send + Sync + 'static>,
) -> SubscriptionHandle
fn subscribe( &self, origin: Self::Origin, callback: Arc<dyn Fn(Self::Event) + Send + Sync + 'static>, ) -> SubscriptionHandle
Subscribe a callback to events of a given origin. The callback is invoked on whatever thread the source publishes from (typically a background thread). The returned handle, when dropped, removes the subscription from the source’s internal registry.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".