amethyst / amethyst/specs

ConvertSaveLoad does not work with entities stored within Vec

Aberta
#681 7 comentários 9 reações 0 responsáveis Ver no GitHub
bug
Linguagem predominante
Rust
Estrelas
2.6k
Forks
215
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

## 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.

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.