mod.rs

Overview

This file defines the CrossRefStorage struct, which provides an abstraction layer for storing and retrieving serialized data blobs using a key-value storage backend. It is designed to work with various implementations of the KeyValueStore trait, allowing flexible storage options including in-memory and Aerospike-based persistence.

The primary responsibility of CrossRefStorage is to manage data blobs identified by a string key (referred to as path in methods) and to serialize/deserialize Rust types transparently using bincode. This facilitates efficient cross-referencing and storage of arbitrary Rust data structures in a binary format.

Structures and Functions

CrossRefStorage

A cloneable struct encapsulating a thread-safe shared reference (Arc) to a key-value store and a string prefix for Aerospike set naming.

Fields

Methods

new(store: impl KeyValueStore + 'static, set_prefix: &str) -> Self

Creates a new CrossRefStorage instance wrapping the provided key-value store implementation and set prefix.

mem() -> CrossRefStorage

Convenience method to create a CrossRefStorage backed by an in-memory store (MemStore) with an empty set prefix.

message_key(&self, hash: &str) -> Key

Generates a key for the storage backend by combining the configured namespace (NAMESPACE constant), the set prefix, and the provided hash string.

read_blob<T: for<'de> Deserialize<'de>>(&self, path: &str) -> anyhow::Result<Option<T>>

Reads and deserializes a data blob stored at the given path.

write_blob<T: Serialize>(&self, path: &str, data: T, until_success: bool) -> anyhow::Result<()>

Serializes and writes the provided data blob into the storage backend under the specified path.

Implementation Details and Algorithms

Interaction with Other System Components

Visual Diagram

classDiagram
class CrossRefStorage {
-store: Arc<KeyValueStore>
-set_prefix: String
+new()
+mem()
-message_key()
+read_blob()
+write_blob()
}
CrossRefStorage ..> KeyValueStore : uses
CrossRefStorage ..> MemStore : can use
CrossRefStorage ..> Key : constructs keys
CrossRefStorage ..> Value : reads/writes bins