std.cell - ZZ
Shared-mutable slots. Pool-backed handles for counters and caches. Each op is explicit — no hidden aliasing. Generic over the stored value type T.
import std.cellPurpose
Section titled “Purpose”std.cell gives you a mutable slot holding a value of any type T. Handles are pool-backed; each op takes the pool lock once. Prefer channels for communication; use cells for shared counters, caches, or config that multiple tasks read/write.
Conceptual model
Section titled “Conceptual model”A cell is a mutable reference cell. cell.new(v) allocates a slot; get/set read/replace; drop releases the handle back to the pool. All ops are fallible (Result) because the pool can reject a dropped/closed handle. Cells share nothing with tasks except through explicit get/set — no data races by construction.
Quickstart
Section titled “Quickstart”import std.cell
c := cell.new(0)cur := cell.get(c).unwrap_or(0)_ := cell.set(c, cur + 1)println(cell.get(c).unwrap_or(-1)) // 1cell.drop(c) // release back to poolMethod syntax
Section titled “Method syntax”Cell handles dispatch method calls: c.get(), c.set(v), c.drop().
import std.cell
func main() -> Result<int, str> { c := cell.new(0) c.set(5)? println(c.get().unwrap_or(-1)) // 5 c.drop() return .ok(0)}Production patterns
Section titled “Production patterns”import std.cellimport std.task
// Shared counter across tasksfunc main() -> Result<int, str> { counter := cell.new(0) for i in 0..8 { task.spawn(|_| { cur := cell.get(counter).unwrap_or(0) match cell.set(counter, cur + 1) { .ok(_) => (), .err(e) => println(e), } }) } // read final value println(cell.get(counter).unwrap_or(0)) cell.drop(counter) return .ok(0)}API reference
Section titled “API reference”4 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.
See also
Section titled “See also”std.env— Environment variables and the surrounding host environment.std.args— argv access and the flag parser: booleans, integers, strings and subcommands.std.process— Spawning, waiting on and signalling child processes.std.log— Log levels, sinks and spans for structured logging.std.sys— Infallible machine information: OS, CPU, memory and uptime.std.path— Pure lexical path manipulation: join, split, extension and normalisation.
Full index: API reference · Standard library