Trait hecs::serialize::row::DeserializeContext
source · pub trait DeserializeContext {
fn deserialize_entity<'de, M>(
&mut self,
map: M,
entity: &mut EntityBuilder
) -> Result<(), M::Error>
where
M: MapAccess<'de>;
}
Available on crate feature
row-serialize
only.Expand description
Implements deserialization of entities from a serde MapAccess
into an EntityBuilder
Data external to the World
can be populated during deserialization by storing mutable
references inside the struct implementing this trait.
Example
use hecs::{*, serialize::row::*};
#[derive(Serialize, Deserialize)]
enum ComponentId { Position, Velocity }
// Could include references to external state for use by `deserialize_entity`
struct Context;
impl DeserializeContext for Context {
fn deserialize_entity<'de, M>(
&mut self,
mut map: M,
entity: &mut EntityBuilder,
) -> Result<(), M::Error>
where
M: serde::de::MapAccess<'de>,
{
while let Some(key) = map.next_key()? {
match key {
ComponentId::Position => {
entity.add::<Position>(map.next_value()?);
}
ComponentId::Velocity => {
entity.add::<Velocity>(map.next_value()?);
}
}
}
Ok(())
}
}
Required Methods§
sourcefn deserialize_entity<'de, M>(
&mut self,
map: M,
entity: &mut EntityBuilder
) -> Result<(), M::Error>where
M: MapAccess<'de>,
fn deserialize_entity<'de, M>(
&mut self,
map: M,
entity: &mut EntityBuilder
) -> Result<(), M::Error>where
M: MapAccess<'de>,
Deserialize a single entity