Skip to content

shared-list

FabricVec<T> is Vec<T> semantics over leased fabric memory. Two tasklets running on different cells hold leases on the same region; both push items; both observe each other’s writes. Order is preserved within a lease generation; lease renewal bumps the generation.

Source

cookbook/shared-list/ in the source tree.

pub fn compute(input: &[u8]) -> Result<AppendOutput, &'static str> {
let mut parsed: AppendInput = serde_json::from_slice(input).map_err(|_| "invalid_input")?;
if parsed.to_append.is_empty() { return Err("empty_append"); }
if parsed.to_append.len() > 1024 { return Err("append_too_large"); }
parsed.current.push(parsed.to_append);
let new_index = parsed.current.len() - 1;
Ok(AppendOutput { list: parsed.current, new_index })
}

What’s interesting

  1. Bounded inputs. Every distributed-collection recipe should bound input size; an unbounded append from one writer can starve memory the other writer needs.
  2. Index returned. The position the new entry landed at is part of the response. In production this is what FabricVec::push() returns — a unique slot index that the lease generation makes safe to reference.
  3. Production drop-in. Replace parsed.current.push(...) with FabricVec::push(...) against memory from grafos-collections::FabricVec::open(lease_ref). The recipe’s current slice becomes whatever FabricVec::iter() returns.