From b7305046cf57221593fab05bf01107c401a00c5b Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Sat, 23 May 2020 22:39:23 -0700 Subject: [PATCH] remove SerializableProperties wrapper struct --- crates/bevy_property/src/properties.rs | 19 ------------------- examples/scene/properties.rs | 14 ++++---------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/crates/bevy_property/src/properties.rs b/crates/bevy_property/src/properties.rs index 8bd9b814a3..c3cf8c7227 100644 --- a/crates/bevy_property/src/properties.rs +++ b/crates/bevy_property/src/properties.rs @@ -1,5 +1,4 @@ use crate::{DynamicProperties, Property, PropertyVal}; -use serde::{ser::SerializeMap, Serialize}; pub trait Properties: Property { fn type_name(&self) -> &str; @@ -75,22 +74,4 @@ where panic!("prop does not exist or is incorrect type: {}", name); } } -} - -pub struct SerializableProperties<'a> { - pub props: &'a dyn Properties, -} - -impl<'a> Serialize for SerializableProperties<'a> { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - let mut state = serializer.serialize_map(Some(self.props.prop_len()))?; - state.serialize_entry("type", self.props.type_name())?; - for (name, prop) in self.props.iter_props() { - state.serialize_entry(name, prop)?; - } - state.end() - } } \ No newline at end of file diff --git a/examples/scene/properties.rs b/examples/scene/properties.rs index 164d13ca7b..3b6276916f 100644 --- a/examples/scene/properties.rs +++ b/examples/scene/properties.rs @@ -1,7 +1,4 @@ -use bevy::{ - prelude::*, - property::SerializableProperties, -}; +use bevy::prelude::*; fn main() { App::build() @@ -24,9 +21,7 @@ pub struct Nested { fn setup() { let mut test = Test { a: 1, - nested: Nested { - b: 8, - } + nested: Nested { b: 8 }, }; // You can set a property value like this. The type must match exactly or this will fail. @@ -47,11 +42,10 @@ fn setup() { test.apply(&patch); assert_eq!(test.a, 4); - // Properties implement the serde Serialize trait. You don't need to derive it yourself! - let ser = SerializableProperties { props: &test }; + // Properties implement the serde Serialize trait. You don't need to derive it yourself! let pretty_config = ron::ser::PrettyConfig::default().with_decimal_floats(true); - let ron_string = ron::ser::to_string_pretty(&ser, pretty_config.clone()).unwrap(); + let ron_string = ron::ser::to_string_pretty(&test, pretty_config.clone()).unwrap(); println!("{}\n", ron_string); // Dynamic properties can be deserialized