pub trait IntoSystem<Params, Marker = bool> {
type System: System + 'static;
// Required method
fn into_system(self, registry: &Registry) -> Self::System;
}Expand description
Converts a plain function into a System.
Accepts two signatures:
fn(params...) -> bool— returns propagation decisionfn(params...)— void return, always propagates (true)
The Marker type parameter (defaulting to bool) distinguishes
between the two. Existing code using IntoSystem<Params> continues
to require -> bool with no changes.
Parameters are resolved from a Registry at conversion time.
§Closures vs named functions
Zero-parameter systems accept closures. For parameterized systems
(one or more Param arguments), Rust’s HRTB + GAT inference
fails on closures — use named functions. Same limitation as
IntoHandler.
§Examples
Bool-returning (scheduler propagation):
use nexus_rt::{WorldBuilder, Res, ResMut, IntoSystem, System, Resource};
#[derive(Resource)]
struct Val(u64);
#[derive(Resource)]
struct Flag(bool);
fn reconcile(val: Res<Val>, mut flag: ResMut<Flag>) -> bool {
if val.0 > 10 {
flag.0 = true;
true
} else {
false
}
}
let mut builder = WorldBuilder::new();
builder.register(Val(42));
builder.register(Flag(false));
let mut world = builder.build();
let mut sys = reconcile.into_system(world.registry());
assert!(sys.run(&mut world));
assert!(world.resource::<Flag>().0);Void-returning (startup, unconditional propagation):
use nexus_rt::{WorldBuilder, ResMut, IntoSystem, System, Resource};
#[derive(Resource)]
struct Val(u64);
fn initialize(mut val: ResMut<Val>) {
val.0 = 42;
}
let mut builder = WorldBuilder::new();
builder.register(Val(0));
let mut world = builder.build();
let mut sys = initialize.into_system(world.registry());
assert!(sys.run(&mut world)); // void → always true
assert_eq!(world.resource::<Val>().0, 42);§Panics
Panics if any Param resource is not registered in
the Registry.
Required Associated Types§
Required Methods§
Sourcefn into_system(self, registry: &Registry) -> Self::System
fn into_system(self, registry: &Registry) -> Self::System
Convert this function into a system, resolving parameters from the registry.