Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

GitHub

This documentation is part of the "Projects with Books" initiative at zenOSmosis.

The source code for this project is available on GitHub.

Extensions Crate

Loading…

Extensions Crate

Relevant source files

The simd-r-drive-extensions crate provides higher-level storage patterns and utilities built on top of the core DataStore extensions/README.md:5-6 These extensions are implemented as Rust traits that extend the functionality of any type implementing DataStoreReader and DataStoreWriter extensions/src/storage_file_import_ext.rs:1-5 extensions/src/lib.rs:7-16

While the core engine focuses on zero-copy binary blobs, the extensions crate introduces structured data handling, automated lifecycle management (TTL), and filesystem integration extensions/README.md:15-134

Extension Architecture

The extensions use a namespacing strategy to prevent key collisions between different types of extended storage and standard raw binary storage. This is achieved using the NamespaceHasher utility extensions/src/storage_file_import_ext.rs:4-5 src/utils.rs:10-11

Extension to Core Mapping

The following diagram illustrates how extension traits map high-level concepts to the underlying DataStore entities.

Diagram: Extension Trait Mapping

graph TD
    subgraph "Natural Language Space"
        "Time-To-Live Cache"["Time-To-Live Cache"] 
        "Explicit Nulls"["Explicit Nulls"]
        "Bulk Directory Import"["Bulk Directory Import"]
end

    subgraph "Code Entity Space"
        "Time-To-Live Cache" --> "StorageCacheExt"["StorageCacheExt"]
        "Explicit Nulls" --> "StorageOptionExt"["StorageOptionExt"]
        "Bulk Directory Import" --> "StorageFileImportExt"["StorageFileImportExt"]
        
        "StorageCacheExt" -- "uses" --> "TTL_PREFIX"["TTL_PREFIX"]
        "StorageOptionExt" -- "uses" --> "OPTION_PREFIX"["OPTION_PREFIX"]
        "StorageFileImportExt" -- "uses" --> "import_dir_recursively"["import_dir_recursively()"]
        
        "TTL_PREFIX" & "OPTION_PREFIX" & "import_dir_recursively" -- "calls" --> "DataStore_write"["DataStore::write() / write_stream()"]
end

Sources: extensions/src/lib.rs:7-16 extensions/README.md:104-106 extensions/src/storage_file_import_ext.rs:90-91


Key Extensions

StorageCacheExt: TTL-Based Caching

The StorageCacheExt trait adds write_with_ttl() and read_with_ttl() methods to the DataStore extensions/README.md:68-70

For details, see StorageCacheExt: TTL-Based Caching.

StorageOptionExt: Explicit None Storage

The StorageOptionExt trait allows users to distinguish between a key that is missing (NotFound) and a key that is explicitly set to None extensions/README.md:17-45

For details, see StorageOptionExt: Explicit None Storage.

StorageFileImportExt: Filesystem Import

This extension provides utilities for syncing local filesystem directories into a DataStore extensions/README.md:89-106

For details, see StorageFileImportExt: Filesystem Import.


Data Flow Overview

The following diagram shows the data flow from high-level extension calls down to the serialized format on disk.

Diagram: Extension Data Flow

sequenceDiagram
    participant App as "Application Code"
    participant Ext as "Extension Trait (e.g., StorageOptionExt)"
    participant Ser as "option_serializer"
    participant DS as "DataStore"

    App->>Ext: write_option(key, None)
    Ext->>Ser: serialize_option(None)
    Ser-->>Ext: [0xFF, 0xFE] (Tombstone)
    Ext->>DS: write(namespaced_key, [0xFF, 0xFE])
    DS-->>App: Result<u64> (Offset)

Sources: extensions/src/utils/option_serializer.rs:24-29 extensions/src/lib.rs:7-8

Summary Table

Extension TraitKey MethodsStorage NamespaceSerialization
StorageCacheExtwrite_with_ttl, read_with_ttlTTL_PREFIXbitcode + 8-byte LE Header
StorageOptionExtwrite_option, read_optionOPTION_PREFIXbitcode or [0xFF, 0xFE]
StorageFileImportExtimport_dir_recursively, open_file_streamOptional User NamespaceRaw Bytes (Streaming)

Sources: extensions/README.md:5-134 extensions/src/utils/option_serializer.rs:24-63 extensions/src/storage_file_import_ext.rs:12-59