Skip to main content

StructureType

Trait StructureType 

Source
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§

Source

fn get_type_id(&self) -> TypeId

Source

fn equals(&self, other: &dyn StructureType) -> bool

We don’t use the equals from rust trait, due to need of dyn compatibility

Source

fn as_any(&self) -> &dyn Any

Source

fn hash(&self) -> u64

Only for local use, do not try to use this in serialize functions

Source

fn clone_unique(&self) -> Box<dyn StructureType>

We don’t use the equals from rust trait, due to need of dyn compatibility

Source

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

Source

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.

Implementors§