Skip to content

Instantly share code, notes, and snippets.

View Aceeri's full-sized avatar
💭
sand is everywhere

Aceeri Aceeri

💭
sand is everywhere
View GitHub Profile
use std::any::Any;
use std::collections::HashMap;
struct VecStorage<T> {
list: Vec<T>,
}
trait Component: Any + Sized {
type Storage: Any + Send + Sync;
struct TypeName {
path: &'static str,
name: &'static str,
lifetimes: Vec<&'static str>,
generics: Option<TypeName>,
}
struct TypeName<'a> {
path: Option<&'static str>,
name: &'static str,
generics: &'a [TypeName<'a>],
}
struct TypeName<'a> {
path: Option<&'static str>,
name: &'static str,
lifetimes: &'a [&'static str],
generics: &'a [TypeName<'a>],
}
---
ComponentName:
field1: true
field2: 0.5
OtherComponentName:
field3: [1, 3, 1]
trait Serializer<T> {
/// Serialize a part of the world into a buffer.
fn serialize(&World, &mut T) { }
/// Deserialize a part of the world from a buffer.
fn deserialize(&mut World, &T) { }
}
pub struct TrackedStorage<F: Component + Default, C: Component, S: UnprotectedStorage<C> + Any + Send + Sync> {
inner_storage: S,
flag: PhantomData<F>,
comp: PhantomData<C>,
}
examples/check.rs
---
#[derive(Debug)]
pub struct ExampleComp1 {
field: bool,
}
impl Component for ExampleComp1 {
type Storage = VecStorage<ExampleComp1>;
/// Helper function for serializing entire storages.
pub fn serialize_storage<C, S>(storage: &Store<C>, serializer: &mut S) -> Result<(), SerializeError>
where C: Component + serde::Serialize + fmt::Debug,
S: serde::Serializer, {
use ::Join;
use ::bitset::BitSetLike;
// probably use `with_capacity` later
let mut sequence: Vec<Option<&C>> = Vec::new();
error[E0277]: the trait bound `&mut D: serde::Deserializer` is not satisfied
--> src\registry.rs:81:44
|
81 | let deserialized: Vec<Option<C>> = serde::Deserialize::deserialize(&mut deserializer).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `serde::Deserializer` is not implemented for `&mut D`
|
= help: consider adding a `where &mut D: serde::Deserializer` bound
= note: required by `serde::Deserialize::deserialize`
pub fn deserialize_storage<C, D, R>(storage: &mut Store<C>, deserializer: &mut D, entities: &[Entity]) -> Result<(), SerializeError>