Skip to content

Commit eb12d3c

Browse files
Add Box<dyn Reflect> to reflection example
1 parent a4387f2 commit eb12d3c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

examples/reflection/reflection.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,20 @@ fn main() {
3232
/// how to handle the field.
3333
/// To do this, you can either define a `#[reflect(default = "...")]` attribute on the ignored field, or
3434
/// opt-out of `FromReflect`'s auto-derive using the `#[reflect(from_reflect = false)]` attribute.
35+
///
36+
/// `Box` will forward all reflect methods to its inner value
3537
#[derive(Reflect)]
3638
#[reflect(from_reflect = false)]
3739
pub struct Foo {
3840
a: usize,
3941
nested: Bar,
42+
boxed: Box<dyn Reflect>,
4043
#[reflect(ignore)]
4144
_ignored: NonReflectedValue,
4245
}
4346

44-
/// This `Bar` type is used in the `nested` field on the `Test` type. We must derive `Reflect` here
45-
/// too (or ignore it)
47+
/// This `Bar` type is used in the `nested` and `boxed` fields on the `Test` type.
48+
/// We must derive `Reflect` here too (or ignore it)
4649
#[derive(Reflect)]
4750
pub struct Bar {
4851
b: usize,
@@ -58,6 +61,7 @@ fn setup(type_registry: Res<AppTypeRegistry>) {
5861
a: 1,
5962
_ignored: NonReflectedValue { _a: 10 },
6063
nested: Bar { b: 8 },
64+
boxed: Box::new(Bar { b: 4 }),
6165
};
6266

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

0 commit comments

Comments
 (0)