Skip to content
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

Adds CustomEntitySerializer to the public API #220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/internals/serialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub enum UnknownType {

/// Describes how to serialize and deserialize a runtime `Entity` ID.
pub trait CustomEntitySerializer {
/// The type used for serialized Entity IDs. Developers should be aware of their
/// serialization/deserialization use-cases as well as world-merge use cases when picking a
/// SerializedID, as the SerializedId type must identify unique entities across world
/// serialization/deserialization cycles as well as across world merges.
type SerializedID: serde::Serialize + for<'a> serde::Deserialize<'a>;
/// Constructs the serializable representation of `Entity`
fn to_serialized(&mut self, entity: Entity) -> Self::SerializedID;
Expand Down
3 changes: 2 additions & 1 deletion src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ pub use crate::internals::serialize::{
de::WorldDeserializer,
id::{Canon, EntityName, EntitySerializer},
ser::{SerializableWorld, WorldSerializer},
AutoTypeKey, DeserializeIntoWorld, DeserializeNewWorld, Registry, TypeKey, UnknownType,
AutoTypeKey, CustomEntitySerializer, DeserializeIntoWorld, DeserializeNewWorld, Registry,
TypeKey, UnknownType,
};

#[cfg(feature = "type-uuid")]
Expand Down