Weave documentation
Forum

Write Tuple

Append a Write record and update the current instance’s tuple map.

Forum::write(Vec<u8>).await appends a JSON TupleEntry::Write { id, tuple } and inserts that tuple in the current instance’s map. It returns the Strand sequence as EntryId. Persistence follows the configured Strand backend; memory-backed Strands are not durable. The Strand lock remains held while acquiring the tuple-map write lock. Concurrent write and take use opposite lock order and can deadlock; externally serialize mixed operations until that implementation is repaired.

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

use std::sync::Arc;
use tokio::sync::RwLock;
use strand::{Strand, StrandConfig};
use forum::Forum;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let dir = tempfile::tempdir()?;
    let cfg = StrandConfig::default().with_storage(dir.path());
    let strand = Arc::new(RwLock::new(Strand::new(cfg).await?));

    let forum = Forum::new(strand);

    // Write a 7-byte tuple. The Forum returns its entry id (also the strand
    // sequence number assigned to this write).
    let id = forum.write(b"hello".to_vec()).await?;
    println!("wrote tuple at entry id {id}");

    Ok(())
}

Source declarations