pub trait StructureType:
Any
+ Send
+ Sync {
// Required methods
fn get_type_id(&self) -> TypeId;
fn equals(&self, other: &dyn StructureType) -> bool;
fn as_any(&self) -> &dyn Any;
fn hash(&self) -> u64;
fn clone_unique(&self) -> Box<dyn StructureType>;
fn get_deserialize_function(
&self,
) -> Box<dyn Fn(u64) -> Box<dyn StructureType>>;
fn get_serialize_function(
&self,
) -> Box<dyn Fn(Box<dyn StructureType>) -> u64>;
}Expand description
The trait for you structure type enum. Needed for proper routing of packets and type safety on serialization/deserialization of data.
You need to create your own structure type for every project.
There are a bunch of functions that already exists, from other traits. They kept manualy due to dyn compatibility.
Required Methods§
fn get_type_id(&self) -> TypeId
Sourcefn equals(&self, other: &dyn StructureType) -> bool
fn equals(&self, other: &dyn StructureType) -> bool
We don’t use the equals from rust trait, due to need of dyn compatibility
fn as_any(&self) -> &dyn Any
Sourcefn clone_unique(&self) -> Box<dyn StructureType>
fn clone_unique(&self) -> Box<dyn StructureType>
We don’t use the equals from rust trait, due to need of dyn compatibility
Sourcefn get_deserialize_function(&self) -> Box<dyn Fn(u64) -> Box<dyn StructureType>>
fn get_deserialize_function(&self) -> Box<dyn Fn(u64) -> Box<dyn StructureType>>
Returns the pointer to function that deserializes value into the current structure type
Sourcefn get_serialize_function(&self) -> Box<dyn Fn(Box<dyn StructureType>) -> u64>
fn get_serialize_function(&self) -> Box<dyn Fn(Box<dyn StructureType>) -> u64>
Returns the pointer to function that serializes structure type value into the u64 value.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".