Trait System

Source
pub trait System: Send + 'static {
    type Request: Request;

    // Required method
    fn run(&mut self, resp: Response<'_, Self::Request>);

    // Provided methods
    fn on_transition(&mut self, from: SystemState, to: SystemState) { ... }
    fn name() -> &'static str { ... }
}
Expand description

System is a type that accesses components, entities, or resoruces.

Fn, FnMut, and FnOnce with certain parameters implement this trait by the crate. Of course struct also can implement this trait. It’s useful when you need some data for a system.

§Examples

Here’s an example of system declaration.


#[derive(Component)] struct Ca;
#[derive(Component)] struct Cb;
#[derive(Component)] struct Cc;
#[derive(Component)] struct Cd;
#[derive(Resource)] struct Ra(i32);
#[derive(Resource)] struct Rb(i32);
#[derive(Resource)] struct Rc(i32);
#[derive(Resource)] struct Rd(i32);

filter!(Fa, Target = Ca); // All, Any, None are ommited for simplicity.
filter!(Fb, Target = Cb);
filter!(Fc, Target = Cc);
filter!(Fd, Target = Cd);
filter!(Fe, All = (Ca, Cb)); // Any and None are ommited for simplicity.
filter!(Ff, All = (Cc, Cd)); // Any and None are ommited for simplicity.

// Function system declaration.

fn system_a(
    r: Read<(Fa, Fb)>, // Read request for the filters.
    w: Write<(Fc, Fd)>, // Write request for the filters.
    rr: ResRead<(Ra, Rb)>, // Read request for the resources.
    rw: ResWrite<(Rc, Rd)>, // Write request for the resources.
    ew: EntWrite<(Fe, Ff)>, // Write request for the filters.
) { /* ... */ }

// Struct system declaration.

request!(Req,
    Read = (Fa, Fb),
    Write = (Fc, Fd),
    ResRead = (Ra, Rb),
    ResWrite = (Rc, Rd),
    EntWrite = (Fe, Ff)
);

struct SystemB;

impl System for SystemB {
    type Request = Req;
    fn run(&mut self, resp: Response<'_, Self::Request>) { /* ... */ }
}

This is another example to show how to add systems to an ECS instance.

use my_ecs::prelude::*;

// Systems do nothing for simplicity.

struct StructSystem {
    data: String,
}

impl System for StructSystem {
    type Request = ();
    fn run(&mut self, resp: Response<'_, Self::Request>) { /* ... */ }
}

let struct_system = StructSystem { data: "".to_owned() };
let fn_system = || {};
let s: String = "".to_owned();
let fn_once_system = move || { drop(s); };

Ecs::default(WorkerPool::new(), [])
    .add_systems((struct_system, fn_system))
    .add_once_system(fn_once_system)
    .unwrap();

Required Associated Types§

Required Methods§

Source

fn run(&mut self, resp: Response<'_, Self::Request>)

Runs the system with the response corresponding to its request.

Provided Methods§

Source

fn on_transition(&mut self, from: SystemState, to: SystemState)

Does a certain behavior on transitions of system state.

See SystemState for more details.

Source

fn name() -> &'static str

Returns system name.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl System for ()

Empty system.

Source§

type Request = ()

Source§

fn run(&mut self, _resp: Response<'_, Self::Request>)

Implementors§

Source§

impl<F> System for FnOnceSystem<(Ph, Ph, Ph, Ph, Ph), F>
where F: FnOnce() + Send + 'static,

Source§

type Request = ((), (), (), (), ())

Source§

impl<F> System for FnSystem<(Ph, Ph, Ph, Ph, Ph), F>
where F: FnMut() + Send + 'static,

Source§

type Request = ((), (), (), (), ())

Source§

impl<F, EW> System for FnOnceSystem<(Ph, Ph, Ph, Ph, EW), F>
where F: FnOnce(EntWrite<'_, EW>) + Send + 'static, EW: EntQueryMut,

Source§

type Request = ((), (), (), (), EW)

Source§

impl<F, EW> System for FnSystem<(Ph, Ph, Ph, Ph, EW), F>
where F: FnMut(EntWrite<'_, EW>) + Send + 'static, EW: EntQueryMut,

Source§

type Request = ((), (), (), (), EW)

Source§

impl<F, R> System for FnOnceSystem<(R, Ph, Ph, Ph, Ph), F>
where F: FnOnce(Read<'_, R>) + Send + 'static, R: Query,

Source§

type Request = (R, (), (), (), ())

Source§

impl<F, R> System for FnSystem<(R, Ph, Ph, Ph, Ph), F>
where F: FnMut(Read<'_, R>) + Send + 'static, R: Query,

Source§

type Request = (R, (), (), (), ())

Source§

impl<F, R, EW> System for FnOnceSystem<(R, Ph, Ph, Ph, EW), F>
where F: FnOnce(Read<'_, R>, EntWrite<'_, EW>) + Send + 'static, R: Query, EW: EntQueryMut,

Source§

type Request = (R, (), (), (), EW)

Source§

impl<F, R, EW> System for FnSystem<(R, Ph, Ph, Ph, EW), F>
where F: FnMut(Read<'_, R>, EntWrite<'_, EW>) + Send + 'static, R: Query, EW: EntQueryMut,

Source§

type Request = (R, (), (), (), EW)

Source§

impl<F, R, RR> System for FnOnceSystem<(R, Ph, RR, Ph, Ph), F>
where F: FnOnce(Read<'_, R>, ResRead<'_, RR>) + Send + 'static, R: Query, RR: ResQuery,

Source§

type Request = (R, (), RR, (), ())

Source§

impl<F, R, RR> System for FnSystem<(R, Ph, RR, Ph, Ph), F>
where F: FnMut(Read<'_, R>, ResRead<'_, RR>) + Send + 'static, R: Query, RR: ResQuery,

Source§

type Request = (R, (), RR, (), ())

Source§

impl<F, R, RR, EW> System for FnOnceSystem<(R, Ph, RR, Ph, EW), F>
where F: FnOnce(Read<'_, R>, ResRead<'_, RR>, EntWrite<'_, EW>) + Send + 'static, R: Query, RR: ResQuery, EW: EntQueryMut,

Source§

type Request = (R, (), RR, (), EW)

Source§

impl<F, R, RR, EW> System for FnSystem<(R, Ph, RR, Ph, EW), F>
where F: FnMut(Read<'_, R>, ResRead<'_, RR>, EntWrite<'_, EW>) + Send + 'static, R: Query, RR: ResQuery, EW: EntQueryMut,

Source§

type Request = (R, (), RR, (), EW)

Source§

impl<F, R, RR, RW> System for FnOnceSystem<(R, Ph, RR, RW, Ph), F>
where F: FnOnce(Read<'_, R>, ResRead<'_, RR>, ResWrite<'_, RW>) + Send + 'static, R: Query, RR: ResQuery, RW: ResQueryMut,

Source§

type Request = (R, (), RR, RW, ())

Source§

impl<F, R, RR, RW> System for FnSystem<(R, Ph, RR, RW, Ph), F>
where F: FnMut(Read<'_, R>, ResRead<'_, RR>, ResWrite<'_, RW>) + Send + 'static, R: Query, RR: ResQuery, RW: ResQueryMut,

Source§

type Request = (R, (), RR, RW, ())

Source§

impl<F, R, RR, RW, EW> System for FnOnceSystem<(R, Ph, RR, RW, EW), F>
where F: FnOnce(Read<'_, R>, ResRead<'_, RR>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, R: Query, RR: ResQuery, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = (R, (), RR, RW, EW)

Source§

impl<F, R, RR, RW, EW> System for FnSystem<(R, Ph, RR, RW, EW), F>
where F: FnMut(Read<'_, R>, ResRead<'_, RR>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, R: Query, RR: ResQuery, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = (R, (), RR, RW, EW)

Source§

impl<F, R, RW> System for FnOnceSystem<(R, Ph, Ph, RW, Ph), F>
where F: FnOnce(Read<'_, R>, ResWrite<'_, RW>) + Send + 'static, R: Query, RW: ResQueryMut,

Source§

type Request = (R, (), (), RW, ())

Source§

impl<F, R, RW> System for FnSystem<(R, Ph, Ph, RW, Ph), F>
where F: FnMut(Read<'_, R>, ResWrite<'_, RW>) + Send + 'static, R: Query, RW: ResQueryMut,

Source§

type Request = (R, (), (), RW, ())

Source§

impl<F, R, RW, EW> System for FnOnceSystem<(R, Ph, Ph, RW, EW), F>
where F: FnOnce(Read<'_, R>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, R: Query, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = (R, (), (), RW, EW)

Source§

impl<F, R, RW, EW> System for FnSystem<(R, Ph, Ph, RW, EW), F>
where F: FnMut(Read<'_, R>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, R: Query, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = (R, (), (), RW, EW)

Source§

impl<F, R, W> System for FnOnceSystem<(R, W, Ph, Ph, Ph), F>
where F: FnOnce(Read<'_, R>, Write<'_, W>) + Send + 'static, R: Query, W: QueryMut,

Source§

type Request = (R, W, (), (), ())

Source§

impl<F, R, W> System for FnSystem<(R, W, Ph, Ph, Ph), F>
where F: FnMut(Read<'_, R>, Write<'_, W>) + Send + 'static, R: Query, W: QueryMut,

Source§

type Request = (R, W, (), (), ())

Source§

impl<F, R, W, EW> System for FnOnceSystem<(R, W, Ph, Ph, EW), F>
where F: FnOnce(Read<'_, R>, Write<'_, W>, EntWrite<'_, EW>) + Send + 'static, R: Query, W: QueryMut, EW: EntQueryMut,

Source§

type Request = (R, W, (), (), EW)

Source§

impl<F, R, W, EW> System for FnSystem<(R, W, Ph, Ph, EW), F>
where F: FnMut(Read<'_, R>, Write<'_, W>, EntWrite<'_, EW>) + Send + 'static, R: Query, W: QueryMut, EW: EntQueryMut,

Source§

type Request = (R, W, (), (), EW)

Source§

impl<F, R, W, RR> System for FnOnceSystem<(R, W, RR, Ph, Ph), F>
where F: FnOnce(Read<'_, R>, Write<'_, W>, ResRead<'_, RR>) + Send + 'static, R: Query, W: QueryMut, RR: ResQuery,

Source§

type Request = (R, W, RR, (), ())

Source§

impl<F, R, W, RR> System for FnSystem<(R, W, RR, Ph, Ph), F>
where F: FnMut(Read<'_, R>, Write<'_, W>, ResRead<'_, RR>) + Send + 'static, R: Query, W: QueryMut, RR: ResQuery,

Source§

type Request = (R, W, RR, (), ())

Source§

impl<F, R, W, RR, EW> System for FnOnceSystem<(R, W, RR, Ph, EW), F>
where F: FnOnce(Read<'_, R>, Write<'_, W>, ResRead<'_, RR>, EntWrite<'_, EW>) + Send + 'static, R: Query, W: QueryMut, RR: ResQuery, EW: EntQueryMut,

Source§

type Request = (R, W, RR, (), EW)

Source§

impl<F, R, W, RR, EW> System for FnSystem<(R, W, RR, Ph, EW), F>
where F: FnMut(Read<'_, R>, Write<'_, W>, ResRead<'_, RR>, EntWrite<'_, EW>) + Send + 'static, R: Query, W: QueryMut, RR: ResQuery, EW: EntQueryMut,

Source§

type Request = (R, W, RR, (), EW)

Source§

impl<F, R, W, RR, RW> System for FnOnceSystem<(R, W, RR, RW, Ph), F>
where F: FnOnce(Read<'_, R>, Write<'_, W>, ResRead<'_, RR>, ResWrite<'_, RW>) + Send + 'static, R: Query, W: QueryMut, RR: ResQuery, RW: ResQueryMut,

Source§

type Request = (R, W, RR, RW, ())

Source§

impl<F, R, W, RR, RW> System for FnSystem<(R, W, RR, RW, Ph), F>
where F: FnMut(Read<'_, R>, Write<'_, W>, ResRead<'_, RR>, ResWrite<'_, RW>) + Send + 'static, R: Query, W: QueryMut, RR: ResQuery, RW: ResQueryMut,

Source§

type Request = (R, W, RR, RW, ())

Source§

impl<F, R, W, RR, RW, EW> System for FnOnceSystem<(R, W, RR, RW, EW), F>
where F: FnOnce(Read<'_, R>, Write<'_, W>, ResRead<'_, RR>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, R: Query, W: QueryMut, RR: ResQuery, RW: ResQueryMut, EW: EntQueryMut,

Source§

impl<F, R, W, RR, RW, EW> System for FnSystem<(R, W, RR, RW, EW), F>
where F: FnMut(Read<'_, R>, Write<'_, W>, ResRead<'_, RR>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, R: Query, W: QueryMut, RR: ResQuery, RW: ResQueryMut, EW: EntQueryMut,

Source§

impl<F, R, W, RW> System for FnOnceSystem<(R, W, Ph, RW, Ph), F>
where F: FnOnce(Read<'_, R>, Write<'_, W>, ResWrite<'_, RW>) + Send + 'static, R: Query, W: QueryMut, RW: ResQueryMut,

Source§

type Request = (R, W, (), RW, ())

Source§

impl<F, R, W, RW> System for FnSystem<(R, W, Ph, RW, Ph), F>
where F: FnMut(Read<'_, R>, Write<'_, W>, ResWrite<'_, RW>) + Send + 'static, R: Query, W: QueryMut, RW: ResQueryMut,

Source§

type Request = (R, W, (), RW, ())

Source§

impl<F, R, W, RW, EW> System for FnOnceSystem<(R, W, Ph, RW, EW), F>
where F: FnOnce(Read<'_, R>, Write<'_, W>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, R: Query, W: QueryMut, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = (R, W, (), RW, EW)

Source§

impl<F, R, W, RW, EW> System for FnSystem<(R, W, Ph, RW, EW), F>
where F: FnMut(Read<'_, R>, Write<'_, W>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, R: Query, W: QueryMut, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = (R, W, (), RW, EW)

Source§

impl<F, RR> System for FnOnceSystem<(Ph, Ph, RR, Ph, Ph), F>
where F: FnOnce(ResRead<'_, RR>) + Send + 'static, RR: ResQuery,

Source§

type Request = ((), (), RR, (), ())

Source§

impl<F, RR> System for FnSystem<(Ph, Ph, RR, Ph, Ph), F>
where F: FnMut(ResRead<'_, RR>) + Send + 'static, RR: ResQuery,

Source§

type Request = ((), (), RR, (), ())

Source§

impl<F, RR, EW> System for FnOnceSystem<(Ph, Ph, RR, Ph, EW), F>
where F: FnOnce(ResRead<'_, RR>, EntWrite<'_, EW>) + Send + 'static, RR: ResQuery, EW: EntQueryMut,

Source§

type Request = ((), (), RR, (), EW)

Source§

impl<F, RR, EW> System for FnSystem<(Ph, Ph, RR, Ph, EW), F>
where F: FnMut(ResRead<'_, RR>, EntWrite<'_, EW>) + Send + 'static, RR: ResQuery, EW: EntQueryMut,

Source§

type Request = ((), (), RR, (), EW)

Source§

impl<F, RR, RW> System for FnOnceSystem<(Ph, Ph, RR, RW, Ph), F>
where F: FnOnce(ResRead<'_, RR>, ResWrite<'_, RW>) + Send + 'static, RR: ResQuery, RW: ResQueryMut,

Source§

type Request = ((), (), RR, RW, ())

Source§

impl<F, RR, RW> System for FnSystem<(Ph, Ph, RR, RW, Ph), F>
where F: FnMut(ResRead<'_, RR>, ResWrite<'_, RW>) + Send + 'static, RR: ResQuery, RW: ResQueryMut,

Source§

type Request = ((), (), RR, RW, ())

Source§

impl<F, RR, RW, EW> System for FnOnceSystem<(Ph, Ph, RR, RW, EW), F>
where F: FnOnce(ResRead<'_, RR>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, RR: ResQuery, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = ((), (), RR, RW, EW)

Source§

impl<F, RR, RW, EW> System for FnSystem<(Ph, Ph, RR, RW, EW), F>
where F: FnMut(ResRead<'_, RR>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, RR: ResQuery, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = ((), (), RR, RW, EW)

Source§

impl<F, RW> System for FnOnceSystem<(Ph, Ph, Ph, RW, Ph), F>
where F: FnOnce(ResWrite<'_, RW>) + Send + 'static, RW: ResQueryMut,

Source§

type Request = ((), (), (), RW, ())

Source§

impl<F, RW> System for FnSystem<(Ph, Ph, Ph, RW, Ph), F>
where F: FnMut(ResWrite<'_, RW>) + Send + 'static, RW: ResQueryMut,

Source§

type Request = ((), (), (), RW, ())

Source§

impl<F, RW, EW> System for FnOnceSystem<(Ph, Ph, Ph, RW, EW), F>
where F: FnOnce(ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = ((), (), (), RW, EW)

Source§

impl<F, RW, EW> System for FnSystem<(Ph, Ph, Ph, RW, EW), F>
where F: FnMut(ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = ((), (), (), RW, EW)

Source§

impl<F, W> System for FnOnceSystem<(Ph, W, Ph, Ph, Ph), F>
where F: FnOnce(Write<'_, W>) + Send + 'static, W: QueryMut,

Source§

type Request = ((), W, (), (), ())

Source§

impl<F, W> System for FnSystem<(Ph, W, Ph, Ph, Ph), F>
where F: FnMut(Write<'_, W>) + Send + 'static, W: QueryMut,

Source§

type Request = ((), W, (), (), ())

Source§

impl<F, W, EW> System for FnOnceSystem<(Ph, W, Ph, Ph, EW), F>
where F: FnOnce(Write<'_, W>, EntWrite<'_, EW>) + Send + 'static, W: QueryMut, EW: EntQueryMut,

Source§

type Request = ((), W, (), (), EW)

Source§

impl<F, W, EW> System for FnSystem<(Ph, W, Ph, Ph, EW), F>
where F: FnMut(Write<'_, W>, EntWrite<'_, EW>) + Send + 'static, W: QueryMut, EW: EntQueryMut,

Source§

type Request = ((), W, (), (), EW)

Source§

impl<F, W, RR> System for FnOnceSystem<(Ph, W, RR, Ph, Ph), F>
where F: FnOnce(Write<'_, W>, ResRead<'_, RR>) + Send + 'static, W: QueryMut, RR: ResQuery,

Source§

type Request = ((), W, RR, (), ())

Source§

impl<F, W, RR> System for FnSystem<(Ph, W, RR, Ph, Ph), F>
where F: FnMut(Write<'_, W>, ResRead<'_, RR>) + Send + 'static, W: QueryMut, RR: ResQuery,

Source§

type Request = ((), W, RR, (), ())

Source§

impl<F, W, RR, EW> System for FnOnceSystem<(Ph, W, RR, Ph, EW), F>
where F: FnOnce(Write<'_, W>, ResRead<'_, RR>, EntWrite<'_, EW>) + Send + 'static, W: QueryMut, RR: ResQuery, EW: EntQueryMut,

Source§

type Request = ((), W, RR, (), EW)

Source§

impl<F, W, RR, EW> System for FnSystem<(Ph, W, RR, Ph, EW), F>
where F: FnMut(Write<'_, W>, ResRead<'_, RR>, EntWrite<'_, EW>) + Send + 'static, W: QueryMut, RR: ResQuery, EW: EntQueryMut,

Source§

type Request = ((), W, RR, (), EW)

Source§

impl<F, W, RR, RW> System for FnOnceSystem<(Ph, W, RR, RW, Ph), F>
where F: FnOnce(Write<'_, W>, ResRead<'_, RR>, ResWrite<'_, RW>) + Send + 'static, W: QueryMut, RR: ResQuery, RW: ResQueryMut,

Source§

type Request = ((), W, RR, RW, ())

Source§

impl<F, W, RR, RW> System for FnSystem<(Ph, W, RR, RW, Ph), F>
where F: FnMut(Write<'_, W>, ResRead<'_, RR>, ResWrite<'_, RW>) + Send + 'static, W: QueryMut, RR: ResQuery, RW: ResQueryMut,

Source§

type Request = ((), W, RR, RW, ())

Source§

impl<F, W, RR, RW, EW> System for FnOnceSystem<(Ph, W, RR, RW, EW), F>
where F: FnOnce(Write<'_, W>, ResRead<'_, RR>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, W: QueryMut, RR: ResQuery, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = ((), W, RR, RW, EW)

Source§

impl<F, W, RR, RW, EW> System for FnSystem<(Ph, W, RR, RW, EW), F>
where F: FnMut(Write<'_, W>, ResRead<'_, RR>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, W: QueryMut, RR: ResQuery, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = ((), W, RR, RW, EW)

Source§

impl<F, W, RW> System for FnOnceSystem<(Ph, W, Ph, RW, Ph), F>
where F: FnOnce(Write<'_, W>, ResWrite<'_, RW>) + Send + 'static, W: QueryMut, RW: ResQueryMut,

Source§

type Request = ((), W, (), RW, ())

Source§

impl<F, W, RW> System for FnSystem<(Ph, W, Ph, RW, Ph), F>
where F: FnMut(Write<'_, W>, ResWrite<'_, RW>) + Send + 'static, W: QueryMut, RW: ResQueryMut,

Source§

type Request = ((), W, (), RW, ())

Source§

impl<F, W, RW, EW> System for FnOnceSystem<(Ph, W, Ph, RW, EW), F>
where F: FnOnce(Write<'_, W>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, W: QueryMut, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = ((), W, (), RW, EW)

Source§

impl<F, W, RW, EW> System for FnSystem<(Ph, W, Ph, RW, EW), F>
where F: FnMut(Write<'_, W>, ResWrite<'_, RW>, EntWrite<'_, EW>) + Send + 'static, W: QueryMut, RW: ResQueryMut, EW: EntQueryMut,

Source§

type Request = ((), W, (), RW, EW)