Skip to main content

ReactorNotify

Struct ReactorNotify 

Source
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

Source

pub fn new(source_capacity: usize, reactor_capacity: usize) -> Self

Create with capacity hints for data sources and reactors.

Source

pub fn register_source(&mut self) -> DataSource

Register a new data source. Returns its identifier.

Slab-backed — removed sources’ slots are reused.

Source

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).

Source

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);
Source

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.

Source

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

Source

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

Source

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.

Source

pub fn unsubscribe(&mut self, reactor: Token, source: DataSource)

Unsubscribe a reactor from a data source.

Source

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.

Source

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.

Source

pub fn has_notified(&self) -> bool

Any reactors woken this frame?

Source

pub fn notified_count(&self) -> usize

Number of reactors woken this frame.

Source

pub fn source_count(&self) -> usize

Number of registered data sources.

Source

pub fn reactor_count(&self) -> usize

Number of registered reactors.

Trait Implementations§

Source§

impl Debug for ReactorNotify

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Resource for ReactorNotify

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.