Attribute Macro dynec::global

source ·
#[global]
Expand description

Derives a Global implementation for the applied type. This macro does not modify the input other than stripping attributes.

The initial argument can be used to specify an initial value for the global. If initial is given without a value, the global will be initialized to Default::default().

This macro calls EntityRef implicitly. Fields that reference entities should be annotated with #[entity].

§Example

#[dynec::global(initial = Foo(5))]
struct Foo(i32);

#[dynec::global(initial)]
#[derive(Default)]
struct Bar(i32);

If a required global state has no initial value and it is not set in the builder, building the world would panic.

#[dynec::global]
struct Qux(i32);

#[dynec::system]
fn test_system(#[dynec(global)] _qux: &Qux) {}

let mut builder = dynec::world::Builder::new(1);
builder.schedule(test_system.build());
builder.build();