Modules / Standard library
std/vec
VecResizeBounded(values, count:s64, maximum_capacity:s64) -> bool has VecResize's initialized-length semantics and caps the backing element capacity. Negative sizes, count above the ceiling or existing capacity above the ceiling fail unchanged; shrinking never silently frees capacity. Bounds logical backing capacity, not allocator/runtime overhead or RSS. VecReserve(values, capacity: s64) -> bool reserves at least that total capacity without changing count. VecResize(values, count: s64) -> bool adjusts initialized length, giving new elements their language defaults and dropping removed owned elements. Both retain capacity on shrink/no-op, reject negative/overflow sizes, and leave storage unchanged on failure. Pass mutable storage, not a pointer; live borrowed views forbid mutation. Owned growable storage. Operations on Vec values are compiler primitives; the data pointer is private to those operations.
Stable Shipped in release v0.4.2.
Import with #import "std/vec".
Vec :: struct($T: Type) { data: *T; count: s64; capacity: s64; }
Text :: struct { bytes: Vec(u8); }Owned UTF-8 text. It moves and drops like the Vec it holds, so its bytes are freed when its owner goes away. TextView(text) borrows it as a string while the Text stays in place, and a Text passed where a string is expected lends the same view. The view cannot outlive the Text, and the Text cannot move or change while a view is live.
TextCopy :: (value: string) -> TextCopy borrowed text into an owned Text; empty when it cannot be allocated.
TextFromBuilder :: (bytes: Vec(u8)) -> TextTake a byte builder's bytes as an owned Text without copying them. BuilderFinish(builder) does the same where a Text is expected.
TextDetach :: (text: Text) -> stringGive up ownership: the returned string keeps the bytes for the rest of the program. A Text call result used where it is not kept as a Text, such as `name := JsonWrite(value)`, detaches this way.
Source ↗ · All modules