pub struct World { /* private fields */ }Expand description
Frozen singleton resource storage.
Analogous to Bevy’s World, but restricted to singleton resources
(no entities, no components, no archetypes).
Created by WorldBuilder::build(). Resources are accessed via
ResourceId direct pointers for O(1) dispatch-time access — a single
pointer deref per fetch, zero framework overhead.
§Safe API
resource/resource_mut— cold-path access via HashMap lookup.
§Unsafe API (framework internals)
The low-level get / get_mut methods are unsafe — used by
Param::fetch for zero-overhead dispatch.
The caller must ensure no mutable aliasing.
Implementations§
Source§impl World
impl World
Sourcepub fn builder() -> WorldBuilder
pub fn builder() -> WorldBuilder
Convenience constructor — returns a new WorldBuilder.
Sourcepub fn registry(&self) -> &Registry
pub fn registry(&self) -> &Registry
Returns a shared reference to the type registry.
Use this for read-only queries (e.g. id,
contains) and construction-time calls
like into_handler.
Sourcepub fn id<T: Resource>(&self) -> ResourceId
pub fn id<T: Resource>(&self) -> ResourceId
Resolve the ResourceId for a type. Cold path — uses HashMap lookup.
§Panics
Panics if the resource type was not registered.
Sourcepub fn try_id<T: Resource>(&self) -> Option<ResourceId>
pub fn try_id<T: Resource>(&self) -> Option<ResourceId>
Try to resolve the ResourceId for a type. Returns None if the
type was not registered.
Sourcepub fn resource<T: Resource>(&self) -> &T
pub fn resource<T: Resource>(&self) -> &T
Safe shared access to a resource. Cold path — resolves via HashMap.
Takes &self — multiple shared references can coexist. The borrow
checker prevents mixing with resource_mut
(which takes &mut self).
§Panics
Panics if the resource type was not registered.
Sourcepub fn resource_mut<T: Resource>(&mut self) -> &mut T
pub fn resource_mut<T: Resource>(&mut self) -> &mut T
Safe exclusive access to a resource. Cold path — resolves via HashMap.
§Panics
Panics if the resource type was not registered.
Sourcepub fn run_startup<F, Params, M>(&mut self, f: F)where
F: IntoSystem<Params, M>,
pub fn run_startup<F, Params, M>(&mut self, f: F)where
F: IntoSystem<Params, M>,
Run a system once with full Param resolution.
Intended for one-shot initialization after build().
Accepts both void-returning (fn(params...)) and bool-returning
(fn(params...) -> bool) functions via IntoSystem.
The return value is always ignored — startup has no DAG to
propagate through. Named functions only (same closure limitation
as IntoHandler).
Can be called multiple times for phased initialization.
§Examples
fn startup(
mut driver: ResMut<MioDriver>,
mut listener: ResMut<Listener>,
) {
// wire drivers to IO sources...
}
let mut world = wb.build();
world.run_startup(startup);Sourcepub fn shutdown_handle(&self) -> ShutdownHandle
pub fn shutdown_handle(&self) -> ShutdownHandle
Returns a ShutdownHandle
sharing the same flag as the world’s shutdown state.
The handle is owned by the event loop and checked each iteration.
Handlers trigger shutdown via the Shutdown Param.
Sourcepub fn run(&mut self, f: impl FnMut(&mut World))
pub fn run(&mut self, f: impl FnMut(&mut World))
Run the event loop until shutdown is triggered.
The closure receives &mut World and defines one iteration of
the poll loop — which drivers to poll, in what order, with what
timeout. The loop exits when a handler calls
Shutdown::trigger or
an external signal flips the flag (see
ShutdownHandle::enable_signals (requires signals feature)).
§Examples
let mut world = wb.build();
world.run_startup(startup);
world.run(|world| {
let now = Instant::now();
let timeout = timer.next_deadline(world)
.map(|d| d.saturating_duration_since(now));
mio.poll(world, timeout).expect("mio poll");
timer.poll(world, now);
});Sourcepub fn current_sequence(&self) -> Sequence
pub fn current_sequence(&self) -> Sequence
Returns the current event sequence number.
Sourcepub fn next_sequence(&mut self) -> Sequence
pub fn next_sequence(&mut self) -> Sequence
Advance to the next event sequence number and return it.
Drivers call this before dispatching each event. The returned sequence number identifies the event being processed.
Sourcepub fn set_sequence(&mut self, seq: Sequence)
pub fn set_sequence(&mut self, seq: Sequence)
Set the current sequence number directly.
Use for recovery / replay — restores the sequence to a known
checkpoint so that subsequent next_sequence calls continue
from the right point.
Sourcepub unsafe fn get<T: 'static>(&self, id: ResourceId) -> &T
pub unsafe fn get<T: 'static>(&self, id: ResourceId) -> &T
Fetch a shared reference to a resource by direct pointer.
§Safety
idmust have been returned byWorldBuilder::registerfor the same builder that produced this container.Tmust be the same type that was registered at thisid.- The caller must ensure no mutable reference to this resource exists.
Sourcepub unsafe fn get_mut<T: 'static>(&self, id: ResourceId) -> &mut T
pub unsafe fn get_mut<T: 'static>(&self, id: ResourceId) -> &mut T
Fetch a mutable reference to a resource by direct pointer.
Takes &self — the container structure is frozen, but individual
resources have interior mutability via raw pointers. Sound because
callers (single-threaded sequential dispatch) uphold no-aliasing.
§Safety
idmust have been returned byWorldBuilder::registerfor the same builder that produced this container.Tmust be the same type that was registered at thisid.- The caller must ensure no other reference (shared or mutable) to this resource exists.
Sourcepub fn register_source(&mut self) -> DataSource
pub fn register_source(&mut self) -> DataSource
Register a new data source for reactor subscriptions.
Convenience for world.resource_mut::<ReactorNotify>().register_source().
Sourcepub fn spawn_reactor<C, Params, F: IntoReactor<C, Params>>(
&mut self,
ctx_fn: impl FnOnce(Token) -> C,
step: F,
) -> ReactorRegistration<'_>
pub fn spawn_reactor<C, Params, F: IntoReactor<C, Params>>( &mut self, ctx_fn: impl FnOnce(Token) -> C, step: F, ) -> ReactorRegistration<'_>
Create and register a reactor from a step function + context factory.
The closure receives the assigned Token so
the reactor can store it for wire routing or self-deregistration.
Params are resolved from the internal registry — single pointer
deref at dispatch time.
This is the primary registration API. It handles the borrow juggling internally: allocates the token, resolves params from the registry, and inserts the reactor — all in one call.
§Example
let src = world.register_source();
world.spawn_reactor(
|id| QuotingCtx { reactor_id: id, instrument: BTC, layer: 1 },
quoting_step,
).subscribe(src);Sourcepub fn spawn_built_reactor(
&mut self,
reactor: impl Reactor + 'static,
) -> ReactorRegistration<'_>
pub fn spawn_built_reactor( &mut self, reactor: impl Reactor + 'static, ) -> ReactorRegistration<'_>
Register a pre-built reactor in one step.
For reactors that don’t need their token in the context, or for
PipelineReactor instances.
Sourcepub fn dispatch_reactors(&mut self) -> bool
pub fn dispatch_reactors(&mut self) -> bool
Dispatch all woken reactors and process deferred removals.
Call this post-frame after event handlers have called
ReactorNotify::mark.
Returns true if any reactor ran.
Sourcepub fn reactor_count(&self) -> usize
pub fn reactor_count(&self) -> usize
Number of registered reactors.