Weave documentation
Rust referenceweave-strand

weave-strand · storage

Source declarations, signatures and documentation for storage.

Source: sigil/weave/models/strand/src/storage.rs. SHA-256: e032dd53a3f17bae8191d6722e2824e3bbf97052fcfb158bbf1f06da7b22d65a.

This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.

storage::StorageError

Storage errors

#[derive(Debug, Error)]
pub enum StorageError {
    /// IO error
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    /// Serialization error
    #[error("Serialization error: {0}")]
    Serialization(String),

    /// Not found
    #[error("Not found")]
    NotFound,
}

Source line: 39.

storage::Info

Storage info

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Info {
/// Current length

pub length: u64,
/// Total byte length

pub byte_length: u64,
/// Downloaded blocks bitfield

pub bitfield: Bitfield,
/// Byte offsets for each block

pub offsets: Vec<u64>
}

Source line: 71.

storage::StorageLockGuard

Process-scoped ownership of a storage mutation lease.

pub trait StorageLockGuard: Send {}

Source line: 86.

storage::Storage

Storage backend trait

pub trait Storage: Send + Sync {
    /// Acquire an exclusive mutation lease for this Strand. Filesystem
    /// implementations must serialize across processes, not only threads.
    fn lock_exclusive(&self) -> Result<Box<dyn StorageLockGuard>, StorageError>;

    /// Read the config
    fn read_config(&self) -> Result<Config, StorageError>;

    /// Write the config
    fn write_config(&self, config: &Config) -> Result<(), StorageError>;

    /// Read the secret key
    fn read_secret_key(&self) -> Result<[u8; 64], StorageError>;

    /// Write the secret key
    fn write_secret_key(&self, key: &[u8; 64]) -> Result<(), StorageError>;

    /// Read info
    fn read_info(&self) -> Result<Info, StorageError>;

    /// Write info
    fn write_info(&self, info: &Info) -> Result<(), StorageError>;

    /// Read data at sequence
    fn read_data(&self, seq: u64) -> Result<Vec<u8>, StorageError>;

    /// Write data at sequence
    fn write_data(&self, seq: u64, data: &[u8]) -> Result<(), StorageError>;

    /// Read header at sequence
    fn read_header(&self, seq: u64) -> Result<Header, StorageError>;

    /// Write header at sequence
    fn write_header(&self, seq: u64, header: &Header) -> Result<(), StorageError>;

    /// Get the byte offset for a sequence number
    fn data_offset(&self, seq: u64) -> Result<u64, StorageError>;

    /// Update offsets after writing data
    fn update_offsets(&self, seq: u64, data_len: u64) -> Result<u64, StorageError>;

    /// Read user metadata key-value store
    fn read_user_kv(&self) -> Result<HashMap<String, Vec<u8>>, StorageError>;

    /// Write user metadata key-value store
    fn write_user_kv(&self, map: &HashMap<String, Vec<u8>>) -> Result<(), StorageError>;
}

Source line: 89.

storage::FileStorage

File-based storage. Flat layout: 8 files per Strand, not two per event. See module docs for the file roster.

Files are opened on-demand per operation rather than cached as long-lived handles. This trades a small amount of throughput for resilience: if a caller wraps the strand path in a TempDir whose Drop deletes the directory between operations (a common pattern in downstream tests), operations will lazily re-create the directory and files instead of failing on stale handles to unlinked inodes.

pub struct FileStorage {

}

Source line: 146.

storage::FileStorage::new

Open or create a Strand directory at path.

Creates the four flat files (data.bin, data.idx, headers.bin, headers.idx) if absent. Existing files are opened append-mode for the .bin twins and read+write for the .idx twins (random-access seeks).

pub fn new(path: impl AsRef<Path>) -> Result<Self, StorageError>;

Source line: 179.

storage::MemoryStorage

In-memory storage

pub struct MemoryStorage {

}

Source line: 687.

storage::MemoryStorage::new

Create new memory storage

pub fn new() -> Self;

Source line: 699.

On this page