Expand description

Envelope Serialization

This module contains the Envelope struct and its related functionality. It allows you to serialize and deserialize LLM chains and other data structures into different formats, such as YAML. The Envelope struct wraps your data and includes additional metadata, which can be useful for managing and organizing your serialized data.

This module is mostly intended for internal use, but you can also use it to serialize your own data structures.

Usage

First, you need to implement the StorableEntity trait for your custom data type, which requires the get_metadata() method. Then, you can use the StorableEntityExt trait to easily read and write your data to and from files.

Example

 use serde::{Deserialize, Serialize};
 use llm_chain::serialization::{Envelope, StorableEntity};

 #[derive(Debug, Clone, Serialize, Deserialize)]
 struct MyData {
    value: i32,
 }

 impl StorableEntity for MyData {
    fn get_metadata() -> Vec<(String, String)> {
        vec![("author".to_string(), "John Doe".to_string())]
    }
 }


 let data = MyData { value: 42 };

 // Convert the data into an envelope
 let envelope = data.clone().write_file_sync("mydata.yaml").unwrap();
 // Serialize the envelope to a YAML file
 let path = "mydata.yaml";
 // Deserialize the envelope from a YAML file
 let read_data = MyData::read_file_sync(path).unwrap();
 assert_eq!(data.value, read_data.value);

Features

This module provides synchronous and asynchronous methods for reading and writing envelopes to and from files. The asynchronous methods are available behind the async feature flag.

Errors

The module also provides the EnvelopeError enum, which represents errors that can occur during serialization, deserialization, and file I/O operations.

Structs

Enums

Traits