Skip to content

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.cell

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.

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.

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)) // 1
cell.drop(c) // release back to pool

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)
}
import std.cell
import std.task
// Shared counter across tasks
func 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)
}

4 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.

Function Signature Description
std.cell.drop drop(c: cell) -> bool Release handle back to pool
std.cell.get get<T>(c: cell) -> Result<T, str> Read current value
std.cell.new new<T>(v: T) -> cell Create a cell holding v
std.cell.set set<T>(c: cell, v: T) -> Result<bool, str> Replace value
  • 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