Trait Serializable

Source
pub trait Serializable:
    Serialize
    + for<'de> Deserialize<'de>
    + Send
    + Sync
    + 'static {
    // Required method
    fn namespace() -> Vec<String>;

    // Provided methods
    fn is_serializable() -> bool { ... }
    fn to_json(&self) -> Result<String> { ... }
    fn to_json_pretty(&self) -> Result<String> { ... }
    fn from_json(json: &str) -> Result<Self>
       where Self: Sized { ... }
    fn to_dict(&self) -> Result<HashMap<String, Value>> { ... }
    fn from_dict(dict: &HashMap<String, Value>) -> Result<Self>
       where Self: Sized { ... }
    fn type_name() -> &'static str { ... }
}
Expand description

Trait for objects that can be serialized and deserialized

This trait provides a standardized way to serialize FerricLink objects to and from various formats, similar to LangChain’s Serializable interface.

Required Methods§

Source

fn namespace() -> Vec<String>

Get the namespace for this serializable object

The namespace is used to identify the type of object when deserializing. It should be a hierarchical path like [“ferriclink”, “messages”, “human”].

Provided Methods§

Source

fn is_serializable() -> bool

Check if this object is serializable

By default, all objects implementing this trait are serializable. Override this method to provide custom serialization logic.

Source

fn to_json(&self) -> Result<String>

Serialize this object to JSON

Source

fn to_json_pretty(&self) -> Result<String>

Serialize this object to a pretty-printed JSON string

Source

fn from_json(json: &str) -> Result<Self>
where Self: Sized,

Deserialize this object from JSON

Source

fn to_dict(&self) -> Result<HashMap<String, Value>>

Serialize this object to a dictionary (HashMap)

Source

fn from_dict(dict: &HashMap<String, Value>) -> Result<Self>
where Self: Sized,

Deserialize this object from a dictionary (HashMap)

Source

fn type_name() -> &'static str

Get the type name for this serializable object

This is used for type identification during serialization/deserialization.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§