Skip to content

Commit 94dab85

Browse files
Add Box<dyn Reflect> to reflection example
1 parent 00cca2f commit 94dab85

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

examples/reflection/reflection.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ fn main() {
2222
/// Deriving `Reflect` implements the relevant reflection traits. In this case, it implements the
2323
/// `Reflect` trait and the `Struct` trait `derive(Reflect)` assumes that all fields also implement
2424
/// Reflect.
25+
/// `Box` will forward all reflect methods to its inner value
2526
#[derive(Reflect)]
2627
pub struct Foo {
2728
a: usize,
2829
nested: Bar,
30+
boxed: Box<dyn Reflect>,
2931
#[reflect(ignore)]
3032
_ignored: NonReflectedValue,
3133
}
3234

33-
/// This `Bar` type is used in the `nested` field on the `Test` type. We must derive `Reflect` here
34-
/// too (or ignore it)
35+
/// This `Bar` type is used in the `nested` and `boxed` fields on the `Test` type.
36+
/// We must derive `Reflect` here too (or ignore it)
3537
#[derive(Reflect)]
3638
pub struct Bar {
3739
b: usize,
@@ -46,6 +48,7 @@ fn setup(type_registry: Res<TypeRegistry>) {
4648
a: 1,
4749
_ignored: NonReflectedValue { _a: 10 },
4850
nested: Bar { b: 8 },
51+
boxed: Box::new(Bar { b: 4 }),
4952
};
5053

5154
// You can set field values like this. The type must match exactly or this will fail.

0 commit comments

Comments
 (0)