diff --git a/content/news/2023-07-07-bevy-0.11/index.md b/content/news/2023-07-07-bevy-0.11/index.md index 61ef369467..a53af19d1c 100644 --- a/content/news/2023-07-07-bevy-0.11/index.md +++ b/content/news/2023-07-07-bevy-0.11/index.md @@ -19,6 +19,32 @@ Since our last release a few months ago we've added a _ton_ of new features, bug * ## WebGPU Support +## Deref Derive Attribute + +
authors: @MrGVSV
+ +Bevy code tends to make heavy use of the [newtype](https://doc.rust-lang.org/rust-by-example/generics/new_types.html) pattern, +which is why we have dedicated derives for [`Deref`](https://docs.rs/bevy/latest/bevy/prelude/derive.Deref.html) and [`DerefMut`](https://docs.rs/bevy/latest/bevy/prelude/derive.DerefMut.html). + +This previously only worked for structs with a single field: + +```rust +#[derive(Resource, Deref, DerefMut)] +struct Score(i32); +``` + +For 0.11, we've improved these derives by adding the `#[deref]` attribute, which allows them to be used on structs with multiple fields. +This makes working with generic newtypes much easier: + +```rust +#[derive(Component, Deref, DerefMut)] +struct Health { + #[deref] // <- use the `health` field as the `Deref` and `DerefMut` target + health: u16, + _character_type: PhantomData, +} +``` +
authors: @mockersf, many others throughout Bevy's development
![webgpu](webgpu.svg)