Skip to content

Commit

Permalink
Revert changes to the reflection example
Browse files Browse the repository at this point in the history
  • Loading branch information
Davier committed Aug 9, 2021
1 parent b9f3b38 commit 15784db
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions examples/reflection/reflection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::{
prelude::*,
reflect::{
serde::{ReflectDeserializer, ReflectSerializer},
DynamicStruct, FromReflect, TypeRegistry,
DynamicStruct, TypeRegistry,
},
};
use serde::de::DeserializeSeed;
Expand All @@ -21,8 +21,8 @@ fn main() {

/// Deriving `Reflect` implements the relevant reflection traits. In this case, it implements the
/// `Reflect` trait and the `Struct` trait `derive(Reflect)` assumes that all fields also implement
/// Reflect, except the ignored fields which should implement `Default`.
#[derive(Reflect, FromReflect)]
/// Reflect.
#[derive(Reflect)]
pub struct Foo {
a: usize,
nested: Bar,
Expand All @@ -32,12 +32,11 @@ pub struct Foo {

/// This `Bar` type is used in the `nested` field on the `Test` type. We must derive `Reflect` here
/// too (or ignore it)
#[derive(Reflect, FromReflect)]
#[derive(Reflect)]
pub struct Bar {
b: usize,
}

#[derive(Default)]
pub struct NonReflectedValue {
_a: usize,
}
Expand Down Expand Up @@ -88,9 +87,6 @@ fn setup(type_registry: Res<TypeRegistry>) {
// DynamicStruct type. "Value types" will be deserialized as themselves.
let _deserialized_struct = reflect_value.downcast_ref::<DynamicStruct>();

// A dynamic type can be converted back into a concrete one using the FromReflect trait
let _deserialized_concrete_value: Foo = Foo::from_reflect(&*reflect_value).unwrap();

// Reflect has its own `partial_eq` implementation, named `reflect_partial_eq`. This behaves
// like normal `partial_eq`, but it treats "dynamic" and "non-dynamic" types the same. The
// `Foo` struct and deserialized `DynamicStruct` are considered equal for this reason:
Expand Down

0 comments on commit 15784db

Please sign in to comment.