bevy/crates/bevy_ecs/src
fluffiac f0704cffa4
Allow a closure to be used as a required component default (#15269)
# Objective

Allow required component default values to be provided in-line.

```rust
#[derive(Component)]
#[require(
    FocusPolicy(block_focus_policy)
)]
struct SomeComponent;

fn block_focus_policy() -> FocusPolicy {
    FocusPolicy::Block
}
```

May now be expressed as:

```rust
#[derive(Component)]
#[require(
    FocusPolicy(|| FocusPolicy::Block)
)]
struct SomeComponent;
```

## Solution

Modified the #[require] proc macro to accept a closure. 

## Testing

Tested using my branch as a dependency, and switching between the inline
closure syntax and function syntax for a bunch of different components.
2024-10-04 00:34:39 +00:00
..
entity Change ReflectMapEntities to operate on components before insertion (#15422) 2024-10-01 18:34:09 +00:00
event Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
identifier Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
observer Rename observe to observe_entity on EntityWorldMut (#15616) 2024-10-03 17:05:26 +00:00
query System param for dynamic resources (#15189) 2024-10-03 18:20:34 +00:00
reflect Change ReflectMapEntities to operate on components before insertion (#15422) 2024-10-01 18:34:09 +00:00
schedule Better warnings about invalid parameters (#15500) 2024-10-03 13:16:55 +00:00
storage Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
system Add method to remove component and all required components for removed component (#15026) 2024-10-03 20:35:08 +00:00
world Add method to remove component and all required components for removed component (#15026) 2024-10-03 20:35:08 +00:00
archetype.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
batching.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bundle.rs Add method to remove component and all required components for removed component (#15026) 2024-10-03 20:35:08 +00:00
change_detection.rs QuerySingle family of system params (#15476) 2024-09-28 19:35:27 +00:00
component.rs Allow a closure to be used as a required component default (#15269) 2024-10-04 00:34:39 +00:00
intern.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
label.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
lib.rs Add method to remove component and all required components for removed component (#15026) 2024-10-03 20:35:08 +00:00
removal_detection.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
traversal.rs Bubbling observers traversal should use query data (#15385) 2024-09-23 18:08:36 +00:00