mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
remove SerializableProperties wrapper struct
This commit is contained in:
parent
4c306e6d48
commit
b7305046cf
2 changed files with 4 additions and 29 deletions
|
@ -1,5 +1,4 @@
|
|||
use crate::{DynamicProperties, Property, PropertyVal};
|
||||
use serde::{ser::SerializeMap, Serialize};
|
||||
|
||||
pub trait Properties: Property {
|
||||
fn type_name(&self) -> &str;
|
||||
|
@ -76,21 +75,3 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SerializableProperties<'a> {
|
||||
pub props: &'a dyn Properties,
|
||||
}
|
||||
|
||||
impl<'a> Serialize for SerializableProperties<'a> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
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()
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
@ -48,10 +43,9 @@ fn setup() {
|
|||
assert_eq!(test.a, 4);
|
||||
|
||||
// Properties implement the serde Serialize trait. You don't need to derive it yourself!
|
||||
let ser = SerializableProperties { props: &test };
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue