Skip to content

Commit caa88b8

Browse files
committed
Automatically add GetTypeRegistration in Reflect derive
1 parent efecaec commit caa88b8

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

crates/bevy_reflect/bevy_reflect_derive/src/derive_data.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<'a> ReflectStruct<'a> {
390390
let bevy_reflect_path = &self.meta().bevy_reflect_path;
391391
WhereClauseOptions {
392392
active_types: self.active_types().into(),
393-
active_trait_bounds: quote! { #bevy_reflect_path::Reflect },
393+
active_trait_bounds: quote! { #bevy_reflect_path::Reflect + #bevy_reflect_path::GetTypeRegistration },
394394
ignored_types: self.ignored_types().into(),
395395
ignored_trait_bounds: quote! { #FQAny + #FQSend + #FQSync },
396396
}
@@ -468,7 +468,7 @@ impl<'a> ReflectEnum<'a> {
468468
let bevy_reflect_path = &self.meta().bevy_reflect_path;
469469
WhereClauseOptions {
470470
active_types: self.active_types().into(),
471-
active_trait_bounds: quote! { #bevy_reflect_path::FromReflect },
471+
active_trait_bounds: quote! { #bevy_reflect_path::FromReflect + #bevy_reflect_path::GetTypeRegistration },
472472
ignored_types: self.ignored_types().into(),
473473
ignored_trait_bounds: quote! { #FQAny + #FQSend + #FQSync + #FQDefault },
474474
}

crates/bevy_reflect/src/enums/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ mod tests {
316316
#[test]
317317
fn enum_should_allow_generics() {
318318
#[derive(Reflect, Debug, PartialEq)]
319-
enum TestEnum<T: FromReflect + GetTypeRegistration> {
319+
enum TestEnum<T: FromReflect> {
320320
A,
321321
B(T),
322322
C { value: T },

crates/bevy_reflect/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ mod tests {
12331233

12341234
// Struct (generic)
12351235
#[derive(Reflect)]
1236-
struct MyGenericStruct<T: Reflect + GetTypeRegistration> {
1236+
struct MyGenericStruct<T> {
12371237
foo: T,
12381238
bar: usize,
12391239
}

examples/reflection/generic_reflection.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Demonstrates how reflection is used with generic Rust types.
22
33
use bevy::prelude::*;
4-
use bevy::reflect::GetTypeRegistration;
54
use std::any::TypeId;
65

76
fn main() {
@@ -13,8 +12,10 @@ fn main() {
1312
.run();
1413
}
1514

15+
/// The `#[derive(Reflect)]` macro will automatically add any required bounds to `T`,
16+
/// such as `Reflect` and `GetTypeRegistration`.
1617
#[derive(Reflect)]
17-
struct MyType<T: Reflect + GetTypeRegistration> {
18+
struct MyType<T> {
1819
value: T,
1920
}
2021

0 commit comments

Comments
 (0)