Weave documentation
Strand

Storage Backends

Flat-file and memory storage selection, integrity and reopening.

A configured path selects FileStorage; no path selects MemoryStorage, whose state disappears with the instance. File storage uses config.json, secret_key, info.json, kv.json, data.bin, data.idx, headers.bin and headers.idx, with separate locking as needed. A file-backed open reuses existing state and checks persisted metadata/key consistency. The secret_key file is private key material; it is not part of a public replication bundle.

This example is checked against source signatures; it was not compiled or run during this documentation pass.

use strand::{FileStorage, MemoryStorage, Strand, StrandConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Open the persisted storage layout in a temporary example directory.
    let durable_dir = tempfile::tempdir()?;
    let _file_backend = FileStorage::new(durable_dir.path())?;

    // The Strand builder picks FileStorage when you supply a path via `with_storage`.
    let cfg = StrandConfig::new().with_storage(durable_dir.path());
    let mut durable = Strand::new(cfg).await?;
    durable.append(b"durable-block").await?;

    // MemoryStorage implements Storage for ephemeral peers.
    // Strand chooses it automatically when no path is configured.
    let mut ephemeral = Strand::new(StrandConfig::new()).await?;
    let _ = MemoryStorage::new(); // referenced to document the explicit constructor
    ephemeral.append(b"in-memory-block").await?;

    println!(
        "durable_path={} durable_len={} ephemeral_len={}",
        durable_dir.path().display(),
        durable.len(),
        ephemeral.len(),
    );
    Ok(())
}

Source declarations