Skip to main content

IntoSystem

Trait IntoSystem 

Source
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 decision
  • fn(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§

Source

type System: System + 'static

The concrete system type produced.

Required Methods§

Source

fn into_system(self, registry: &Registry) -> Self::System

Convert this function into a system, resolving parameters from the registry.

Implementors§

Source§

impl<F: Send + 'static, P0: Param + 'static> IntoSystem<(P0,)> for F
where for<'a> &'a mut F: FnMut(P0) -> bool + FnMut(P0::Item<'a>) -> bool,

Source§

impl<F: Send + 'static, P0: Param + 'static> IntoSystem<(P0,), ()> for F
where for<'a> &'a mut F: FnMut(P0) + FnMut(P0::Item<'a>),

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static> IntoSystem<(P0, P1)> for F
where for<'a> &'a mut F: FnMut(P0, P1) -> bool + FnMut(P0::Item<'a>, P1::Item<'a>) -> bool,

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static> IntoSystem<(P0, P1), ()> for F
where for<'a> &'a mut F: FnMut(P0, P1) + FnMut(P0::Item<'a>, P1::Item<'a>),

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static> IntoSystem<(P0, P1, P2)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2) -> bool + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>) -> bool,

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static> IntoSystem<(P0, P1, P2), ()> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>),

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static> IntoSystem<(P0, P1, P2, P3)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3) -> bool + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>) -> bool,

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static> IntoSystem<(P0, P1, P2, P3), ()> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>),

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static> IntoSystem<(P0, P1, P2, P3, P4)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4) -> bool + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>) -> bool,

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static> IntoSystem<(P0, P1, P2, P3, P4), ()> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>),

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static, P5: Param + 'static> IntoSystem<(P0, P1, P2, P3, P4, P5)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4, P5) -> bool + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>, P5::Item<'a>) -> bool,

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static, P5: Param + 'static> IntoSystem<(P0, P1, P2, P3, P4, P5), ()> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4, P5) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>, P5::Item<'a>),

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static, P5: Param + 'static, P6: Param + 'static> IntoSystem<(P0, P1, P2, P3, P4, P5, P6)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4, P5, P6) -> bool + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>, P5::Item<'a>, P6::Item<'a>) -> bool,

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static, P5: Param + 'static, P6: Param + 'static> IntoSystem<(P0, P1, P2, P3, P4, P5, P6), ()> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4, P5, P6) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>, P5::Item<'a>, P6::Item<'a>),

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static, P5: Param + 'static, P6: Param + 'static, P7: Param + 'static> IntoSystem<(P0, P1, P2, P3, P4, P5, P6, P7)> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4, P5, P6, P7) -> bool + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>, P5::Item<'a>, P6::Item<'a>, P7::Item<'a>) -> bool,

Source§

impl<F: Send + 'static, P0: Param + 'static, P1: Param + 'static, P2: Param + 'static, P3: Param + 'static, P4: Param + 'static, P5: Param + 'static, P6: Param + 'static, P7: Param + 'static> IntoSystem<(P0, P1, P2, P3, P4, P5, P6, P7), ()> for F
where for<'a> &'a mut F: FnMut(P0, P1, P2, P3, P4, P5, P6, P7) + FnMut(P0::Item<'a>, P1::Item<'a>, P2::Item<'a>, P3::Item<'a>, P4::Item<'a>, P5::Item<'a>, P6::Item<'a>, P7::Item<'a>),

Source§

impl<F: FnMut() + Send + 'static> IntoSystem<(), ()> for F

Source§

impl<F: FnMut() -> bool + Send + 'static> IntoSystem<()> for F