legion icon indicating copy to clipboard operation
legion copied to clipboard

How to serialize components with Entity fields?

Open rodya-mirov opened this issue 5 years ago • 2 comments

Suppose I have some kind of Component struct with a target: Entity field on it. If I [derive(Serialize, Deserialize)] on that struct, what I discover is that Entity is not (de)serializable.

error[E0277]: the trait bound `legion_core::entity::Entity: components::_IMPL_DESERIALIZE_FOR_Position::_serde::Deserialize<'_>` is not satisfied
   --> src/components.rs:195:5
    |
195 |     pub item: Entity,
    |     ^^^ the trait `components::_IMPL_DESERIALIZE_FOR_Position::_serde::Deserialize<'_>` is not implemented for `legion_core::entity::Entity`
    |
    = note: required by `components::_IMPL_DESERIALIZE_FOR_Position::_serde::de::MapAccess::next_value`

I recall that in specs there was quite a bit of boilerplate involving markers to get this to work. Unfortunately the documentation is not yet present for serialize (which in fact is in master, but is not yet published on crates.io, which is 6 months behind master). The lone example has a lot of boilerplate code which doesn't seem game-specific (should it be part of the library?), including some unsafe, but gives no examples of de/serializing any Entity.

Can we get an example of that?

rodya-mirov avatar May 25 '20 01:05 rodya-mirov

It's not implemented yet afaik. Feel free to do so 😁 If you would like a more extensive example or framework for serializing entities, please take a look at my prefab repository: https://github.com/kabergstrom/prefab/

kabergstrom avatar May 27 '20 19:05 kabergstrom

Related: #52

singalen avatar Aug 02 '21 03:08 singalen