bevy/crates/bevy_pbr/src
Carter Anderson 538afe2330
Improved Require Syntax (#18555)
# Objective

Requires are currently more verbose than they need to be. People would
like to define inline component values. Additionally, the current
`#[require(Foo(custom_constructor))]` and `#[require(Foo(|| Foo(10))]`
syntax doesn't really make sense within the context of the Rust type
system. #18309 was an attempt to improve ergonomics for some cases, but
it came at the cost of even more weirdness / unintuitive behavior. Our
approach as a whole needs a rethink.

## Solution

Rework the `#[require()]` syntax to make more sense. This is a breaking
change, but I think it will make the system easier to learn, while also
improving ergonomics substantially:

```rust
#[derive(Component)]
#[require(
    A, // this will use A::default()
    B(1), // inline tuple-struct value
    C { value: 1 }, // inline named-struct value
    D::Variant, // inline enum variant
    E::SOME_CONST, // inline associated const
    F::new(1), // inline constructor
    G = returns_g(), // an expression that returns G
    H = SomethingElse::new(), // expression returns SomethingElse, where SomethingElse: Into<H> 
)]
struct Foo;
```

## Migration Guide

Custom-constructor requires should use the new expression-style syntax:

```rust
// before
#[derive(Component)]
#[require(A(returns_a))]
struct Foo;

// after
#[derive(Component)]
#[require(A = returns_a())]
struct Foo;
```

Inline-closure-constructor requires should use the inline value syntax
where possible:

```rust
// before
#[derive(Component)]
#[require(A(|| A(10))]
struct Foo;

// after
#[derive(Component)]
#[require(A(10)]
struct Foo;
```

In cases where that is not possible, use the expression-style syntax:

```rust
// before
#[derive(Component)]
#[require(A(|| A(10))]
struct Foo;

// after
#[derive(Component)]
#[require(A = A(10)]
struct Foo;
```

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: François Mockers <mockersf@gmail.com>
2025-03-26 17:48:27 +00:00
..
atmosphere bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
cluster bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
decal Improved Require Syntax (#18555) 2025-03-26 17:48:27 +00:00
deferred Remove prepasses from the render world when they're removed from the main world. (#17565) 2025-02-14 06:43:35 +00:00
light bugfix(frustra of point lights were not recalculated when a camera changes) (#18519) 2025-03-25 04:48:49 +00:00
light_probe bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
lightmap bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
meshlet Move non-generic parts of the PrepassPipeline to internal field (#18322) 2025-03-25 18:47:31 +00:00
prepass Move non-generic parts of the PrepassPipeline to internal field (#18322) 2025-03-25 18:47:31 +00:00
render Fix unecessary specialization checks for apps with many materials (#18410) 2025-03-19 06:22:39 +00:00
ssao Add bevy_anti_aliasing (#18323) 2025-03-19 18:40:32 +00:00
ssr bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
volumetric_fog bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
components.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
extended_material.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
fog.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
lib.rs Add missing system ordering constraint to prepare_lights (#18308) 2025-03-15 22:57:52 +00:00
material_bind_groups.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
material.rs Fix specialize_shadows system ordering (#18412) 2025-03-19 06:40:45 +00:00
mesh_material.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
parallax.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
pbr_material.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
wireframe.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00