pub struct ReactorNotify { /* private fields */ }Expand description
Reactor storage, interest mapping, and notification hub.
Lives in the World as a resource. Handles:
- Reactor registration and storage (
Box<dyn Reactor>in a slab) - Data source registration and interest mapping
- Marking data sources as changed (fan-out + dedup)
Event handlers access this via ResMut<ReactorNotify>
to mark data sources or register new reactors at runtime.
Implementations§
Source§impl ReactorNotify
impl ReactorNotify
Sourcepub fn new(source_capacity: usize, reactor_capacity: usize) -> Self
pub fn new(source_capacity: usize, reactor_capacity: usize) -> Self
Create with capacity hints for data sources and reactors.
Sourcepub fn register_source(&mut self) -> DataSource
pub fn register_source(&mut self) -> DataSource
Register a new data source. Returns its identifier.
Slab-backed — removed sources’ slots are reused.
Sourcepub fn remove_source(&mut self, source: DataSource)
pub fn remove_source(&mut self, source: DataSource)
Remove a data source. Unsubscribes all reactors and frees the slab slot for reuse.
Marking a removed DataSource is a no-op (stale handle safety).
Sourcepub fn create_reactor(&mut self) -> Token
pub fn create_reactor(&mut self) -> Token
Reserve a slot for a new reactor and return its Token.
Use with insert_reactor to complete registration.
This two-phase pattern avoids borrow conflicts: you can
drop the &mut ReactorNotify borrow, build the reactor with
world.registry(), then call insert.
§Example
// Phase 1: reserve slot
let token = world.resource_mut::<ReactorNotify>().create_reactor();
// Phase 2: build reactor (borrows &World for registry)
let reactor = quoting_step.into_reactor(
QuotingCtx { reactor_id: token, instrument: BTC },
world.registry(),
);
// Phase 3: fill slot
world.resource_mut::<ReactorNotify>()
.insert_reactor(token, reactor)
.subscribe(btc_md);Sourcepub fn insert_reactor(
&mut self,
token: Token,
reactor: impl Reactor + 'static,
) -> ReactorRegistration<'_>
pub fn insert_reactor( &mut self, token: Token, reactor: impl Reactor + 'static, ) -> ReactorRegistration<'_>
Insert a pre-built reactor at a previously allocated Token.
The token must have been returned by create_reactor
and not yet filled. Completes the two-phase registration.
§Panics
Panics if the token was not allocated by create_reactor or was
already filled.
Sourcepub fn register<C, Params, F: IntoReactor<C, Params>>(
&mut self,
ctx_fn: impl FnOnce(Token) -> C,
step: F,
registry: &Registry,
) -> ReactorRegistration<'_>
pub fn register<C, Params, F: IntoReactor<C, Params>>( &mut self, ctx_fn: impl FnOnce(Token) -> C, step: F, registry: &Registry, ) -> ReactorRegistration<'_>
Register a reactor from a step function + context factory.
One-shot convenience when you already have &Registry (e.g.,
inside event handlers via Param resolution, or in tests).
For the safe World-based API, use create_reactor
Sourcepub fn register_built(
&mut self,
reactor: impl Reactor + 'static,
) -> ReactorRegistration<'_>
pub fn register_built( &mut self, reactor: impl Reactor + 'static, ) -> ReactorRegistration<'_>
Register a pre-built reactor in one step.
Convenience for reactors that don’t need their Token in
the context. For reactors that need the token (wire routing,
self-deregistration), use create_reactor
Sourcepub fn subscribe(&mut self, reactor: Token, source: DataSource)
pub fn subscribe(&mut self, reactor: Token, source: DataSource)
Subscribe a reactor to a data source.
Idempotent — subscribing twice is a no-op.
No-op if source has been removed.
Sourcepub fn unsubscribe(&mut self, reactor: Token, source: DataSource)
pub fn unsubscribe(&mut self, reactor: Token, source: DataSource)
Unsubscribe a reactor from a data source.
Sourcepub fn mark(&mut self, source: DataSource)
pub fn mark(&mut self, source: DataSource)
Mark a data source as changed this frame.
Fans out to all subscribed reactor tokens in the underlying
LocalNotify, with per-reactor dedup.
Sourcepub fn remove_reactor(&mut self, token: Token)
pub fn remove_reactor(&mut self, token: Token)
Remove a reactor and unsubscribe from all data sources.
Uses the reverse index for O(subscriptions) removal instead of scanning all data source interest lists.
Sourcepub fn has_notified(&self) -> bool
pub fn has_notified(&self) -> bool
Any reactors woken this frame?
Sourcepub fn notified_count(&self) -> usize
pub fn notified_count(&self) -> usize
Number of reactors woken this frame.
Sourcepub fn source_count(&self) -> usize
pub fn source_count(&self) -> usize
Number of registered data sources.
Sourcepub fn reactor_count(&self) -> usize
pub fn reactor_count(&self) -> usize
Number of registered reactors.