-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConvertSaveLoad does not work with entities stored within Vec #681
Comments
I ended up working around this with a transparent new type for vector. There may be a simpler way to push this in to the core saveload functionality. I had to use a newtype wrapper in my code as neither ConvertSaveload or Vec are local types and rust won't allow implementation without at least one type being local to the crate.
|
Thanks for posting that @Azaril, it works! |
Same problem appears with Option<Entity>. I suppose a similar workaround is needed for any Entity container? |
@TheRealHnefi yes - unfortunately that's the case. Here's a snippet of the code I use for some of the containers. It's not perfect as if you end up with entities that are deleted but still being serialized you can panic on deserialize.
|
Oh wow, thanks for the wrappers! |
Just for clarity, are you OK with me copying that and redistributing under MIT or BSD as part of another project? Or do you have it as a crate somewhere? |
Yes - you're free to do whatever you want with the code. You can use it as public domain. |
Description
When using ConvertSaveLoad to derive the serialize/deserialize behavior for a struct, if that structure contains a Vec (or other container) that implements Serde::Serialize the entities stored within cannot be serialized. This appears to be due to the Serde serialization path being used on the container and its contents from that point forward instead of the ConvertSaveLoad serialization path.
Due to the specificity of the traits used for the generated derive code, it's not possible to override the behavior for just the Vec (or other collection) case.
Meta
Rust version: rustc 1.42.0-nightly
Specs version / commit: 0.15
Operating system: Windows 10
Reproduction
Expected behavior
Entities can be serialized in collections.
The text was updated successfully, but these errors were encountered: