Skip to content

Commit

Permalink
Remove WorldSerializer in favor of a serialize method on World.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceeri committed Jul 8, 2017
1 parent 7df74b5 commit 2a0277d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust
rust:
- nightly-2017-06-19
- nightly-2017-06-20
- beta
- stable

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub use storage::{MergeError, PackedData};
pub mod common;

#[cfg(feature="serialize")]
pub use world::{WorldSerializer, WorldDeserializer};
pub use world::WorldDeserializer;

/// A wrapper for a fetched `Entities` resource.
/// Note that this is just `Fetch<Entities>`, so
Expand Down
42 changes: 11 additions & 31 deletions src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,15 @@ impl World {
}
}
}

#[cfg(feature = "serialize")]
/// Serializes the component in the world using the group as a "filter".
pub fn serialize<G, S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where G: SerializeGroup,
S: Serializer,
{
G::serialize_group(self, serializer)
}
}

impl Default for World {
Expand Down Expand Up @@ -795,44 +804,15 @@ mod tests {
}
}

#[cfg(feature="serialize")]
/// Structure used to serialize a world using a component group.
pub struct WorldSerializer<'a, G> {
world: &'a World,
phantom: PhantomData<G>,
}

#[cfg(feature="serialize")]
impl<'a, G> WorldSerializer<'a, G> {
/// Creates a new world serializer out of a world.
pub fn new(world: &'a World) -> WorldSerializer<'a, G> {
WorldSerializer {
world: world,
phantom: PhantomData,
}
}
}

#[cfg(feature="serialize")]
impl<'a, G> Serialize for WorldSerializer<'a, G>
where G: ComponentGroup + SerializeGroup
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
G::serialize_group(self.world, serializer)
}
}

#[cfg(feature="serialize")]
#[cfg(feature = "serialize")]
/// Structure used for stateful deserialization into the world using a component group.
pub struct WorldDeserializer<'a, G> {
world: &'a mut World,
entities: &'a [Entity],
phantom: PhantomData<G>,
}

#[cfg(feature="serialize")]
#[cfg(feature = "serialize")]
impl<'a, G> WorldDeserializer<'a, G> {
/// Creates a new world deserializer out of a world and a list of entities.
///
Expand Down

0 comments on commit 2a0277d

Please sign in to comment.