You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bevy code tends to make heavy use of the [newtype](https://doc.rust-lang.org/rust-by-example/generics/new_types.html) pattern,
27
+
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).
28
+
29
+
This previously only worked for structs with a single field:
30
+
31
+
```rust
32
+
#[derive(Resource, Deref, DerefMut)]
33
+
structScore(i32);
34
+
```
35
+
36
+
For 0.11, we've improved these derives by adding the `#[deref]` attribute, which allows them to be used on structs with multiple fields.
37
+
This makes working with generic newtypes much easier:
38
+
39
+
```rust
40
+
#[derive(Component, Deref, DerefMut)]
41
+
structHealth<T:Character> {
42
+
#[deref] // <- use the `health` field as the `Deref` and `DerefMut` target
43
+
health:u16,
44
+
_character_type:PhantomData<T>,
45
+
}
46
+
```
47
+
22
48
<divclass="release-feature-authors">authors: @mockersf, many others throughout Bevy's development</div>
0 commit comments