ConvertSaveLoad does not work with entities stored within Vec
- Lingua principale
- Rust
- Stelle
- 2.6k
- Fork
- 215
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
## 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
```rust
use specs::*;
use specs::error::NoError;
use specs::saveload::*;
use specs_derive::*;
use serde::{Serialize, Deserialize};
extern crate serde;
extern crate specs;
extern crate specs_derive;
#[derive(Clone, Debug, ConvertSaveload)]
pub struct TestStruct {
some_entities: Vec
}
fn main() {
println!("Hello, world!");
}
// Uncomment to see conflicting implementation.
/*
impl ConvertSaveload for Vec
where for<'de> M: Deserialize<'de>,
{
type Data = Vec;
type Error = NoError;
fn convert_into(&self, mut ids: F) -> Result
where
F: FnMut(Entity) -> Option
{
let markers = self.0.iter()
.filter_map(|entity| ids(*entity))
.collect();
Ok(markers)
}
fn convert_from(data: Self::Data, mut ids: F) -> Result
where
F: FnMut(M) -> Option
{
let entities = data.iter()
.filter_map(|marker| ids(marker.clone()))
.collect();
Ok(entities)
}
}
```
## Expected behavior
Entities can be serialized in collections.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.