Bevy "scope" 它的系统如何基于参数的类型?

How does Bevy "scope" its systems based on the type of the arguments?

Bevy, a new Rust game engine and ECS, has a feature where it "scopes" its systems based on the type of the arguments. From its docs:

The parameters we pass in to a "system function" define what entities the system runs on. In this case, greet_people will run on all entities with the Person and Name component.

看起来像这样:

struct Person;
struct Name(String);

fn greet_people(person: &Person, name: &Name) {
    println!("hello {}", name.0);
}

Bevy 如何做到这一点?我以为我在某处读到 Rust 不支持这种方式的反射。

Bevy 定义了一组特征 (IntoQuerySystem and IntoForEachSystem),这些特征由匹配这些签名的函数实现。这些特征随后由 Bevy prelude 导出。这样做的一个局限是你只能将函数转换到系统中的参数数量达到一定数量,并且参数必须按照特定的顺序([command?], [resources...], [queries/components...]).

编辑:For-each 系统在 Bevy 0.4 中被弃用。