Skip to content

Commit bfe8d0d

Browse files
committed
when meta attribute is specified, automatically call .meta()
All example, test, and documentation code now registers components using world.component::<T>() without chaining .meta(). The derive macro is updated to automatically invoke .meta() when required, simplifying user code and reducing boilerplate.
1 parent 73b677d commit bfe8d0d

16 files changed

+20
-89
lines changed

flecs_ecs/examples/flecs/reflection/entity_type.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ pub struct TypeWithEntity {
1111
fn main() {
1212
let mut world = World::new();
1313

14-
// Using Entity directly would resolve to a u64 datatype, so
15-
// use flecs::meta::Entity instead.
16-
world.component::<TypeWithEntity>().meta();
17-
1814
/* Alternatively, you can do it manually like so (without the derive macro)
1915
.member(Entity::id(),"e", 1, core::mem::offset_of!(TypeWithEntity, e));
2016
*/

flecs_ecs/examples/flecs/reflection/reflection_basics.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ pub struct Position {
1212
fn main() {
1313
let mut world = World::new();
1414

15-
// Register the Position component
16-
world.component::<Position>().meta();
17-
18-
/* Alternatively, you can do it manually like so (without the derive macro)
15+
/* Alternatively without the meta attribute,
16+
you can do it manually like so (without the derive macro)
1917
.member(f32::id(),"x", 1 /* count */, core::mem::offset_of!(Position, x))
2018
.member(f32::id(),"y", 1, core::mem::offset_of!(Position, y));
2119
*/

flecs_ecs/examples/flecs/reflection/reflection_basics_deserialize.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ pub struct Position {
1212
fn main() {
1313
let world = World::new();
1414

15-
// Register the Position component with reflection data
16-
world.component::<Position>().meta();
17-
18-
/* Alternatively, you can do it manually like so (without the derive macro)
15+
/* Alternatively when not using meta attribute,
16+
you can do it manually like so (without the derive macro)
1917
.member(f32,"x", 1 /* count */, core::mem::offset_of!(Position, x))
2018
.member(f32,"y", 1, core::mem::offset_of!(Position, y));
2119
*/

flecs_ecs/examples/flecs/reflection/reflection_basics_json.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ pub struct Position {
1212
fn main() {
1313
let mut world = World::new();
1414

15-
// Register the Position component with reflection data
16-
world.component::<Position>().meta();
17-
18-
/* Alternatively, you can do it manually like so (without the derive macro)
15+
/* Alternatively without the meta attribute,
16+
you can do it manually like so (without the derive macro)
1917
.member(f32::id(),"x", 1 /* count */, core::mem::offset_of!(Position, x))
2018
.member(f32::id(),"y", 1, core::mem::offset_of!(Position, y));
2119
*/

flecs_ecs/examples/flecs/reflection/reflection_basics_simple_enum.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@ pub struct TypeWithEnum {
2020
fn main() {
2121
let mut world = World::new();
2222

23-
// Register the Color component
24-
world.component::<Color>().meta();
25-
/* Alternatively, you can do it manually like so (without the derive macro)
23+
/* Alternatively without the meta attribute,
24+
you can do it manually like so (without the derive macro)
2625
.constant("Red", Color::Red as i32)
2726
.constant("Green", Color::Green as i32)
2827
.constant("Blue", Color::Blue as i32);
2928
*/
3029

31-
// Register the TypeWithEnum component
32-
world.component::<TypeWithEnum>().meta();
33-
34-
/* Alternatively, you can do it manually like so (without the derive macro)
30+
/* Alternatively without the meta attribute,
31+
you can do it manually like so (without the derive macro)
3532
.member(Color::id(),"color", 1, core::mem::offset_of!(TypeWithEnum, color));
3633
*/
3734

flecs_ecs/examples/flecs/reflection/reflection_nested_set_member.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ pub struct Line {
1919
fn main() {
2020
let world = World::new();
2121

22-
world.component::<Point>().meta();
23-
24-
world.component::<Line>().meta();
25-
2622
// Create entity, set value of Line using reflection API
2723
let e = world.entity().add(Line::id());
2824

flecs_ecs/examples/flecs/reflection/reflection_nested_struct.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ pub struct Line {
1919
fn main() {
2020
let world = World::new();
2121

22-
world.component::<Point>().meta();
23-
world.component::<Line>().meta();
24-
2522
// Create entity, set Line component
2623
let e = world.entity().set(Line {
2724
start: Point { x: 10.0, y: 20.0 },

flecs_ecs/examples/flecs/reflection/reflection_query_to_custom_json.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ pub struct Mass {
2929
fn main() {
3030
let world = World::new();
3131

32-
// Register components with reflection data
33-
world.component::<Position>().meta();
34-
35-
world.component::<Velocity>().meta();
36-
37-
world.component::<Mass>().meta();
38-
3932
world
4033
.entity_named("a")
4134
.set(Position { x: 10.0, y: 20.0 })

flecs_ecs/examples/flecs/reflection/reflection_query_to_json.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ pub struct Mass {
2525
fn main() {
2626
let world = World::new();
2727

28-
// Register components with reflection data
29-
world.component::<Position>().meta();
30-
31-
world.component::<Velocity>().meta();
32-
33-
world.component::<Mass>().meta();
34-
3528
world
3629
.entity_named("a")
3730
.set(Position { x: 10.0, y: 20.0 })

flecs_ecs/examples/flecs/reflection/reflection_ser_std_string.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ struct StringComponent {
1818
fn main() {
1919
let world = World::new();
2020

21-
// Register component with std::string members
22-
world.component::<StringComponent>().meta();
23-
2421
// Create value & serialize it
2522
let mut v = StringComponent {
2623
a: "foo".to_string(),

0 commit comments

Comments
 (0)