evo_framework/framework/entity/
ientity.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::framework::ievo::IEvo;
use std::error::Error;

/// A base trait representing an object-safe entity, commonly used for 
/// serialization, deserialization, and string representation.
pub trait IEntity: IEvo {
    /// Serializes the object into a vector of bytes.
    ///
    /// # Returns
    ///
    /// - `Ok(Vec<u8>)` containing the serialized bytes if successful.
    /// - `Err(Box<dyn Error>)` if serialization fails.
    fn to_bytes(&self) -> Result<Vec<u8>, Box<dyn Error>>;

    /// Deserializes an object from a slice of bytes.
    ///
    /// # Arguments
    ///
    /// - `data` - A slice of bytes representing the serialized object.
    ///
    /// # Returns
    ///
    /// - `Ok(Self)` if deserialization is successful.
    /// - `Err(Box<dyn Error>)` if deserialization fails.
    fn from_bytes(data: &[u8]) -> Result<Self, Box<dyn Error>>
    where
        Self: Sized;

    /// Outputs a human-readable string representation of the object.
    fn to_string(&self) -> String;
}