Generated Directly from Source — All parameter inputs, return outputs, types, and trait blocks below are extracted directly from the 18 embedded modules in kit/*.stag, paired with worked input/output examples.

Stag Standard Kit API Reference

The Stag Standard Kit comprises 18 modules embedded directly inside the stagc binary at compile time. Every module below documents its exact exported types, traits, constants, parameter inputs, return outputs, and a worked Stag example with expected output. Every module is verified by a native Stag test suite (kit/tests/<module>_tests.stag) at both -O0 and -O2.

Module Index

ModuleImport PathNative Test SuiteSummary
kit.allocuse kit.allockit/tests/alloc_tests.stagportable heap allocation backed by ISO C libc.
kit.argsuse kit.argskit/tests/args_tests.stagcommand-line argument inspection (kit::args). Populated automatically by the Stag startup entry point from C (argc, argv).
kit.checkuse kit.checkkit/tests/check_tests.stagTest assertions and runtime invariant checks.
kit.hashuse kit.hashkit/tests/hash_tests.stagfast 64-bit hashing (Hasher, Hash) and primitive Eq impls.
kit.iouse kit.iokit/tests/io_tests.stagcross-platform console and RAII file I/O backed by ISO C stdio.
kit.jsonuse kit.jsonkit/tests/json_tests.stagRFC 8259 JSON parser, validator, DOM, RFC 6901 JSON Pointer, and compact / pretty serializer.
kit.listuse kit.listkit/tests/list_tests.staggeneric heap-allocated growable array (List<T>). Full RAII Drop support for elements, Index/IndexMut, in-place sorting, and for-compatible ListIter<T>.
kit.mathuse kit.mathkit/tests/math_tests.staginteger and floating-point math utilities backed by native hardware LLVM math intrinsics and pure IEEE-754 operations.
kit.maybeuse kit.maybekit/tests/maybe_tests.stagoptional value container (Maybe<T>). Directly compatible with ? propagation and for iterator protocols.
kit.memuse kit.memkit/tests/mem_tests.staglow-level memory manipulation utilities.
kit.outcomeuse kit.outcomekit/tests/outcome_tests.stagfallible result container (Outcome<T, E>). Directly compatible with postfix ? error propagation.
kit.pathuse kit.pathkit/tests/path_tests.stagcross-platform file path manipulation (kit::path). Handles both POSIX / and Windows \ separators cleanly.
kit.randuse kit.randkit/tests/rand_tests.stagDeterministic pseudo-random number generation (Xoshiro256** + SplitMix64). All 64-bit mixing operations are overflow-free under checked Stag arithmetic.
kit.scribeuse kit.scribekit/tests/scribe_tests.stagzero-overhead formatting traits (Scribe, Show) and helpers.
kit.sysuse kit.syskit/tests/sys_tests.stagportable process and environment utilities backed by ISO C stdlib.
kit.tableuse kit.tablekit/tests/table_tests.staggeneric open-addressing hash table (Table<K: Eq + Hash, V>). Uses linear probing with tombstones, power-of-2 capacities, automatic rehashing, for-compatible TableIter<K, V>, and full RAII Drop safety for both keys and values.
kit.textuse kit.textkit/tests/text_tests.stagowned, growable, NUL-terminated UTF-8 string (Text). Maintains a trailing NUL byte so as_cstr() is O(1) with zero allocation for C FFI.
kit.timeuse kit.timekit/tests/time_tests.stagwall-clock timestamps, monotonic high-resolution clocks, duration helpers, stopwatch timer, and sleep utilities.

Detailed Module Specifications

kit.alloc

Stag Standard Kit: portable heap allocation backed by ISO C libc.

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
alloc_bytessize: i64*mut u8
alloc_zeroedsize: i64*mut u8
realloc_bytesptr: *mut u8, new_size: i64*mut u8
dealloc_bytesptr: *mut u8unit
alloc_array[T]count: i64*mut T
realloc_array[T]ptr: *mut T, new_count: i64*mut T
dealloc_array[T]ptr: *mut Tunit

Worked Example (kit.alloc)

stag
use kit.alloc
use kit.io (Console)

func main() -> i32:
    buf := alloc.alloc_zeroed(4)
    *ptr_offset(buf, 0) = 65u8
    *ptr_offset(buf, 1) = 66u8
    *ptr_offset(buf, 2) = 67u8
    s := str_from_raw(buf, 3)
    Console.println(s)
    alloc.dealloc_bytes(buf)
    0i32

Expected Output:

text
ABC

kit.args

Stag Standard Kit: command-line argument inspection (kit::args). Populated automatically by the Stag startup entry point from C (argc, argv).

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
count*(none)*i64
getidx: i64Maybe[str]
program_name*(none)*str
all*(none)*List[str]
has_flagflag: strbool
flag_valueflag: strMaybe[Text]

Worked Example (kit.args)

stag
use kit.args
use kit.io (Console)

func main() -> i32:
    n := args.count()
    prog := args.at(0).unwrap_or("")
    msg := f"argc={n} argv[0]={prog}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
argc=1 argv[0]=./app

kit.check

Stag Standard Kit: Test assertions and runtime invariant checks.

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
failmsg: strnever
assertcond: bool, msg: strunit
okcond: boolunit
eq_i32actual: i32, expected: i32, label: strunit
eq_i64actual: i64, expected: i64, label: strunit
ne_i64actual: i64, unexpected: i64, label: strunit
lt_i64actual: i64, bound: i64, label: strunit
le_i64actual: i64, bound: i64, label: strunit
gt_i64actual: i64, bound: i64, label: strunit
ge_i64actual: i64, bound: i64, label: strunit
eq_u64actual: u64, expected: u64, label: strunit
eq_boolactual: bool, expected: bool, label: strunit
eq_stractual: str, expected: str, label: strunit
ne_stractual: str, unexpected: str, label: strunit
contains_strhaystack: str, needle: str, label: strunit
eq_textactual: *Text, expected: str, label: strunit
near_f64actual: f64, expected: f64, eps: f64, label: strunit
pub func eq[T: Eq](actual: *T, expected: *T, label: str)—unit
pub func ne[T: Eq](actual: *T, unexpected: *T, label: str)—unit
is_some[T]m: *Maybe[T], label: strunit
is_none[T]m: *Maybe[T], label: strunit
pub func is_ok[T, E](o: *Outcome[T, E], label: str)—unit
pub func is_err[T, E](o: *Outcome[T, E], label: str)—unit

Worked Example (kit.check)

stag
use kit.check

test "arithmetic invariants":
    check.eq_i64(6 * 7, 42, "product")
    check.gt_i64(42, 10, "lower bound")
    check.near_f64(0.1 + 0.2, 0.3, 1e-12, "ieee754 tolerance")
    check.contains_str("stag-0.1.0", "0.1", "version substring")

Expected Output:

text
[PASS] arithmetic invariants
Summary: 1 passed, 0 failed (total 1)

kit.hash

Stag Standard Kit: fast 64-bit hashing (Hasher, Hash) and primitive Eq impls.

Types, Traits & Constants

stag
pub record Hasher
pub trait Hash

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
pub func hash_of[T: Hash](v: *T) -> u64—unit

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
Hashernew*(none)*Hasher
Hasherwrite_u8mut self, b: u8unit
Hasherwrite_u64mut self, v: u64unit
Hasherwrite_i64mut self, v: i64unit
Hasherwrite_bytesmut self, ptr: *u8, len: i64unit
Hasherwrite_strmut self, s: strunit
Hasherfinishin selfu64
i8 : Eqeqin self, o: *i8bool
i16 : Eqeqin self, o: *i16bool
i32 : Eqeqin self, o: *i32bool
i64 : Eqeqin self, o: *i64bool
u8 : Eqeqin self, o: *u8bool
u16 : Eqeqin self, o: *u16bool
u32 : Eqeqin self, o: *u32bool
u64 : Eqeqin self, o: *u64bool
bool : Eqeqin self, o: *boolbool
str : Eqeqin self, o: *strbool
i8 : Hashhashin self, h: *mut Hasherunit
i16 : Hashhashin self, h: *mut Hasherunit
i32 : Hashhashin self, h: *mut Hasherunit
i64 : Hashhashin self, h: *mut Hasherunit
u8 : Hashhashin self, h: *mut Hasherunit
u16 : Hashhashin self, h: *mut Hasherunit
u32 : Hashhashin self, h: *mut Hasherunit
u64 : Hashhashin self, h: *mut Hasherunit
bool : Hashhashin self, h: *mut Hasherunit
str : Hashhashin self, h: *mut Hasherunit

Worked Example (kit.hash)

stag
use kit.hash (Hash, Hasher, hash_of)
use kit.io (Console)

record Key:
    id: i64
    tag: u8

attach Key : Hash:
    func hash(in self, h: *mut Hasher):
        h.write_i64(self.id)
        h.write_u8(self.tag)

func main() -> i32:
    k1 := Key { id: 7, tag: 1u8 }
    k2 := Key { id: 7, tag: 1u8 }
    same := hash_of(&k1) == hash_of(&k2)
    msg := f"equal_hashes={same}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
equal_hashes=true

kit.io

Stag Standard Kit: cross-platform console and RAII file I/O backed by ISO C stdio.

Types, Traits & Constants

stag
pub record Console
pub record File

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
read_filepath: strOutcome[Text, i32]
read_linespath: strOutcome[List[Text], i32]
write_filepath: str, content: strOutcome[unit, i32]
append_filepath: str, content: strOutcome[unit, i32]
remove_filepath: strbool
file_existspath: strbool

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
Consoleout*(none)*Console
Consoleprints: strunit
Consoleprintlns: strunit
Consoleprint_i64n: i64unit
Consoleprintln_i64n: i64unit
Consoleflush*(none)*unit
Consoleread_line*(none)*Outcome[Text, i32]
Console : Scribewrite_strmut self, s: strunit
Console : Scribewrite_bytemut self, b: u8unit
Fileopen_readpath: strOutcome[File, i32]
Fileopen_writepath: strOutcome[File, i32]
Fileopen_appendpath: strOutcome[File, i32]
Fileis_openin selfbool
Filewrite_bytesmut self, data: []u8Outcome[i64, i32]
Filewrite_strmut self, s: strOutcome[i64, i32]
Fileread_allmut selfOutcome[Text, i32]
Fileflushmut selfOutcome[unit, i32]
Fileclosemut selfunit
File : Scribewrite_strmut self, s: strunit
File : Scribewrite_bytemut self, b: u8unit
File : Dropdropmut selfunit

Worked Example (kit.io)

stag
use kit.io
use kit.io (Console)

func main() -> i32:
    p := "demo_io.txt"
    _ := io.write_file(p, "alpha\nbeta\n")
    content := io.read_file(p).unwrap()
    Console.print(content.as_str())
    _ := io.remove_file(p)
    0i32

Expected Output:

text
alpha
beta

kit.json

Stag Standard Kit: RFC 8259 JSON parser, validator, DOM, RFC 6901 JSON Pointer, and compact / pretty serializer.

Types, Traits & Constants

stag
pub const DEFAULT_MAX_DEPTH: i64 = 128
pub choice Json

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
parse_with_max_depthinput: str, max_depth: i64Outcome[Json, Text]
parseinput: strOutcome[Json, Text]
validate_with_max_depthinput: str, max_depth: i64Outcome[unit, Text]
validateinput: strOutcome[unit, Text]

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
Jsonnull_val*(none)*Json
Jsonbool_valv: boolJson
Jsonint_valv: i64Json
Jsonfloat_valv: f64Json
Jsonstr_vals: strJson
Jsontext_valt: TextJson
Jsonarray*(none)*Json
Jsonarray_with_capcap: i64Json
Jsonobject*(none)*Json
Jsonobject_with_capcap: i64Json
Jsonis_nullin selfbool
Jsonis_boolin selfbool
Jsonis_intin selfbool
Jsonis_floatin selfbool
Jsonis_numberin selfbool
Jsonis_strin selfbool
Jsonis_arrayin selfbool
Jsonis_objectin selfbool
Jsonas_boolin selfMaybe[bool]
Jsonas_intin selfMaybe[i64]
Jsonas_i64in selfMaybe[i64]
Jsonas_f64in selfMaybe[f64]
Jsonas_numin selfMaybe[f64]
Jsonas_strin selfMaybe[str]
Jsonas_arrin selfMaybe[*List[Json]]
Jsonas_arr_mutmut selfMaybe[*mut List[Json]]
Jsonas_objin selfMaybe[*Table[Text, Json]]
Jsonas_obj_mutmut selfMaybe[*mut Table[Text, Json]]
Jsonget_indexin self, idx: i64Maybe[*Json]
Jsonget_index_mutmut self, idx: i64Maybe[*mut Json]
Jsonget_keyin self, key: strMaybe[*Json]
Jsonget_key_mutmut self, key: strMaybe[*mut Json]
Jsonhas_keyin self, key: strbool
Jsonlenin selfi64
Jsonis_emptyin selfbool
Jsonpushmut self, val: Jsonbool
Jsonsetmut self, key: str, val: Jsonbool
Jsonremove_keymut self, key: strMaybe[Json]
Jsonpointerin self, path: strMaybe[*Json]
Jsonpointer_mutmut self, path: strMaybe[*mut Json]
Jsonclonein selfJson
Jsonequalsin self, other: *Jsonbool
Jsonwrite_toin self, out: *mut Textunit
Jsonwrite_pretty_toin self, out: *mut Text, indent: i64unit
Jsonstringifyin selfText
Jsonstringify_with_capin self, cap: i64Text
Jsonstringify_prettyin self, indent: i64Text
Jsonstringify_pretty_with_capin self, indent: i64, cap: i64Text
Json : Eqeqin self, other: *Jsonbool

Worked Example (kit.json)

stag
use kit.io (Console)
use kit.json

func main() -> i32:
    doc := json.parse("{\"lang\":\"stag\",\"ver\":[0,1,0]}").unwrap()
    lang := doc.get("lang").unwrap().as_str().unwrap()
    minor := doc.get("ver").unwrap().at(1).unwrap().as_i64().unwrap()
    out := json.stringify(&doc)
    msg := f"lang={lang} minor={minor} raw={out}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
lang=stag minor=1 raw={"lang":"stag","ver":[0,1,0]}

kit.list

Stag Standard Kit: generic heap-allocated growable array (List<T>). Full RAII Drop support for elements, Index/IndexMut, in-place sorting, and for-compatible ListIter<T>.

Types, Traits & Constants

stag
pub record ListIter[T]
pub record List[T]

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
attach[T] ListIter[T]nextmut selfMaybe[*T]
attach[T] List[T]new*(none)*List[T]
attach[T] List[T]with_capcap: i64List[T]
attach[T] List[T]lenin selfi64
attach[T] List[T]capin selfi64
attach[T] List[T]is_emptyin selfbool
attach[T] List[T]reservemut self, additional: i64unit
attach[T] List[T]pushmut self, value: Tunit
attach[T] List[T]popmut selfMaybe[T]
attach[T] List[T]getin self, idx: i64Maybe[*T]
attach[T] List[T]get_mutmut self, idx: i64Maybe[*mut T]
attach[T] List[T]firstin selfMaybe[*T]
attach[T] List[T]lastin selfMaybe[*T]
attach[T] List[T]insertmut self, idx: i64, value: Tunit
attach[T] List[T]removemut self, idx: i64T
attach[T] List[T]swap_removemut self, idx: i64T
attach[T] List[T]reversemut selfunit
attach[T] List[T]sort_bymut self, cmp: func(*T, *T) -> i32unit
attach[T] List[T]find_indexin self, pred: func(*T) -> boolMaybe[i64]
attach[T] List[T]contains_byin self, pred: func(*T) -> boolbool
attach[T] List[T]clearmut selfunit
attach[T] List[T]as_slicein self[]T
attach[T] List[T]as_mut_slicemut self[]mut T
attach[T] List[T]iterin selfListIter[T]
attach[T] List[T] : Indexindexin self, i: i64*Self.Output
attach[T] List[T] : IndexMutindex_mutmut self, i: i64*mut Self.Output
attach[T] List[T] : Dropdropmut selfunit

Worked Example (kit.list)

stag
use kit.io (Console)
use kit.list (List)

func cmp_i64(a: *i64, b: *i64) -> i32:
    if *a < *b then -1i32 elif *a > *b then 1i32 else 0i32

func main() -> i32:
    var xs = List[i64].new()
    xs.push(30)
    xs.push(10)
    xs.push(20)
    xs.sort_by(cmp_i64)
    msg := f"len={xs.len()} sorted=[{*xs.get(0).unwrap()}, {*xs.get(1).unwrap()}, {*xs.get(2).unwrap()}]"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
len=3 sorted=[10, 20, 30]

kit.math

Stag Standard Kit: integer and floating-point math utilities backed by native hardware LLVM math intrinsics and pure IEEE-754 operations.

Types, Traits & Constants

stag
pub const PI: f64 = 3.1415926535897931
pub const TAU: f64 = 6.2831853071795862
pub const E: f64 = 2.7182818284590451
pub const SQRT2: f64 = 1.4142135623730951
pub const func abs_i64(x: i64) -> i64 = if x < 0 then -x else x
pub const func min_i64(a: i64, b: i64) -> i64 = if a < b then a else b
pub const func max_i64(a: i64, b: i64) -> i64 = if a > b then a else b
pub const func clamp_i64(x: i64, lo: i64, hi: i64) -> i64:
pub const func gcd_i64(a: i64, b: i64) -> i64:
pub const func lcm_i64(a: i64, b: i64) -> i64:
pub const func pow_i64(base: i64, exp_val: i64) -> i64:
pub const func min_f64(a: f64, b: f64) -> f64 = if a < b then a else b
pub const func max_f64(a: f64, b: f64) -> f64 = if a > b then a else b
pub const func clamp_f64(x: f64, lo: f64, hi: f64) -> f64:
pub const func lerp_f64(a: f64, b: f64, t: f64) -> f64 = a + (b - a) * t

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
sqrtx: f64f64
sqrt_f64x: f64f64
sqrt_f32x: f32f32
fma_f64a: f64, b: f64, c: f64f64
fma_f32a: f32, b: f32, c: f32f32
sin_f64x: f64f64
cos_f64x: f64f64
tan_f64x: f64f64
asin_f64x: f64f64
acos_f64x: f64f64
atan_f64x: f64f64
atan2_f64y: f64, x: f64f64
exp_f64x: f64f64
ln_f64x: f64f64
log10_f64x: f64f64
pow_f64base: f64, exponent: f64f64
floor_f64x: f64f64
ceil_f64x: f64f64
round_f64x: f64f64
trunc_f64x: f64f64
abs_f64x: f64f64
abs_f32x: f32f32
fmod_f64x: f64, y: f64f64
hypot_f64x: f64, y: f64f64

Worked Example (kit.math)

stag
use kit.io (Console)
use kit.math

func main() -> i32:
    h := math.hypot_f64(3.0, 4.0)
    g := math.gcd_i64(84, 30)
    c := math.clamp_i64(150, 0, 100)
    msg := f"hypot={h} gcd={g} clamp={c}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
hypot=5 gcd=6 clamp=100

kit.maybe

Stag Standard Kit: optional value container (Maybe<T>). Directly compatible with ? propagation and for iterator protocols.

Types, Traits & Constants

stag
pub choice Maybe[T]

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
attach[T] Maybe[T]unwrapselfT
attach[T] Maybe[T]unwrap_orself, fallback: TT
attach[T] Maybe[T]map[U]self, f: func(T) -> UMaybe[U]
attach[T] Maybe[T]and_then[U]self, f: func(T) -> Maybe[U]Maybe[U]
attach[T] Maybe[T]takemut selfMaybe[T]

Worked Example (kit.maybe)

stag
use kit.io (Console)
use kit.maybe (Maybe)

func double_i64(x: i64) -> i64 = x * 2

func main() -> i32:
    a := Maybe[i64].Some(21).map(double_i64).unwrap_or(0)
    b: Maybe[i64] := Maybe.None
    msg := f"a={a} b={b.unwrap_or(-1)}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
a=42 b=-1

kit.mem

Stag Standard Kit: low-level memory manipulation utilities.

Types, Traits & Constants

stag
pub const func size_of[T]() -> i64 = sizeof(T)
pub const func align_of[T]() -> i64 = alignof(T)

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
swap[T]a: *mut T, b: *mut Tunit
replace[T]dst: *mut T, value: TT
zero_bytesdst: *mut u8, len: i64unit
bytes_eqa: *u8, b: *u8, len: i64bool
bytes_cmpa: *u8, b: *u8, len: i64i32

Worked Example (kit.mem)

stag
use kit.io (Console)
use kit.mem

func main() -> i32:
    var a: i64 = 10
    var b: i64 = 99
    mem.swap(&mut a, &mut b)
    prev := mem.replace(&mut a, 50)
    msg := f"a={a} b={b} prev={prev}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
a=50 b=10 prev=99

kit.outcome

Stag Standard Kit: fallible result container (Outcome<T, E>). Directly compatible with postfix ? error propagation.

Types, Traits & Constants

stag
pub choice Outcome[T, E]

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
attach[T, E] Outcome[T, E]unwrapselfT
attach[T, E] Outcome[T, E]unwrap_orself, fallback: TT
attach[T, E] Outcome[T, E]unwrap_errselfE
attach[T, E] Outcome[T, E]map[U]self, f: func(T) -> UOutcome[U, E]
attach[T, E] Outcome[T, E]map_err[F]self, f: func(E) -> FOutcome[T, F]
attach[T, E] Outcome[T, E]okselfMaybe[T]
attach[T, E] Outcome[T, E]errselfMaybe[E]

Worked Example (kit.outcome)

stag
use kit.io (Console)
use kit.outcome (Outcome)

func safe_div(a: i64, b: i64) -> Outcome[i64, str]:
    if b == 0:
        return Outcome.Err("divide by zero")
    Outcome.Ok(a / b)

func main() -> i32:
    ok_v := safe_div(84, 2).unwrap_or(0)
    err_flag := safe_div(10, 0).is_err()
    msg := f"ok={ok_v} err={err_flag}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
ok=42 err=true

kit.path

Stag Standard Kit: cross-platform file path manipulation (kit::path). Handles both POSIX / and Windows \ separators cleanly.

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
joina: str, b: strText
file_namep: strText
parentp: strText
extensionp: strText
stemp: strText
has_extensionp: str, ext: strbool
normalize_slashesp: strText

Worked Example (kit.path)

stag
use kit.io (Console)
use kit.path

func main() -> i32:
    joined := path.join("src/compiler", "sema.stag")
    st := path.stem(joined.as_str())
    ex := path.extension(joined.as_str())
    msg := f"joined={joined} stem={st} ext={ex}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
joined=src/compiler/sema.stag stem=sema ext=stag

kit.rand

Stag Standard Kit: Deterministic pseudo-random number generation (Xoshiro256** + SplitMix64). All 64-bit mixing operations are overflow-free under checked Stag arithmetic.

Types, Traits & Constants

stag
pub record Rng

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
Rngfrom_seedseed: u64Rng
Rngfrom_time*(none)*Rng
Rngnext_u64mut selfu64
Rngnext_i64mut selfi64
Rngrange_u64mut self, bound: u64u64
Rngrange_i64mut self, lo: i64, hi: i64i64
Rngnext_f64mut selff64
Rngchancemut self, probability: f64bool
Rngshuffle[T]mut self, xs: *mut List[T]unit

Worked Example (kit.rand)

stag
use kit.io (Console)
use kit.rand (Rng)

func main() -> i32:
    var rng = Rng.from_seed(42u64)
    roll := rng.range_i64(1, 7)
    unit := rng.next_f64()
    msg := f"roll={roll} in_unit={unit >= 0.0 && unit < 1.0}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
roll=4 in_unit=true

kit.scribe

Stag Standard Kit: zero-overhead formatting traits (Scribe, Show) and helpers.

Types, Traits & Constants

stag
pub trait Scribe
pub trait Show

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
pub func to_text[T: Show](val: *T) -> Text—unit
format_i64val: i64Text
format_f64val: f64Text
format_hexval: u64Text

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
Text : Scribewrite_strmut self, s: strunit
Text : Scribewrite_bytemut self, b: u8unit
i8 : Showshowin self, out: *mut Textunit
i16 : Showshowin self, out: *mut Textunit
i32 : Showshowin self, out: *mut Textunit
i64 : Showshowin self, out: *mut Textunit
u8 : Showshowin self, out: *mut Textunit
u16 : Showshowin self, out: *mut Textunit
u32 : Showshowin self, out: *mut Textunit
u64 : Showshowin self, out: *mut Textunit
f32 : Showshowin self, out: *mut Textunit
f64 : Showshowin self, out: *mut Textunit
bool : Showshowin self, out: *mut Textunit
str : Showshowin self, out: *mut Textunit
Text : Showshowin self, out: *mut Textunit

Worked Example (kit.scribe)

stag
use kit.io (Console)
use kit.scribe (Scribe, Show, format_hex, to_text)
use kit.text (Text)

func main() -> i32:
    var buf = Text.new()
    buf.write_str("mask=")
    buf.write_hex(255u64)
    buf.write_str(" ok=")
    buf.write_bool(true)
    n := 2026
    msg := f"{buf} year={to_text(&n)} hex={format_hex(16u64)}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
mask=0xff ok=true year=2026 hex=0x10

kit.sys

Stag Standard Kit: portable process and environment utilities backed by ISO C stdlib.

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
exit_processcode: i32never
abort_process*(none)*never
env_getname: strMaybe[Text]
env_hasname: strbool

Worked Example (kit.sys)

stag
use kit.io (Console)
use kit.sys

func main() -> i32:
    has_path := sys.env_has("PATH")
    missing := sys.env_get("STAG_UNSET_ENV").is_none()
    msg := f"has_path={has_path} missing={missing}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
has_path=true missing=true

kit.table

Stag Standard Kit: generic open-addressing hash table (Table<K: Eq + Hash, V>). Uses linear probing with tombstones, power-of-2 capacities, automatic rehashing, for-compatible TableIter<K, V>, and full RAII Drop safety for both keys and values.

Types, Traits & Constants

stag
pub record TableEntry[K, V]
pub record TableIter[K, V]
pub record Table[K: Eq + Hash, V]

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
attach[K, V] TableIter[K, V]nextmut selfMaybe[TableEntry[K, V]]
attach[K: Eq + Hash, V] Table[K, V]new*(none)*Table[K, V]
attach[K: Eq + Hash, V] Table[K, V]with_capmin_cap: i64Table[K, V]
attach[K: Eq + Hash, V] Table[K, V]lenin selfi64
attach[K: Eq + Hash, V] Table[K, V]capin selfi64
attach[K: Eq + Hash, V] Table[K, V]is_emptyin selfbool
attach[K: Eq + Hash, V] Table[K, V]reservemut self, additional: i64unit
attach[K: Eq + Hash, V] Table[K, V]setmut self, key: K, value: VMaybe[V]
attach[K: Eq + Hash, V] Table[K, V]find_by_hash[Q]in self, h: u64, query: *Q, eq_fn: func(*K, *Q) -> booli64
attach[K: Eq + Hash, V] Table[K, V]get_by_hash[Q]in self, h: u64, query: *Q, eq_fn: func(*K, *Q) -> boolMaybe[*V]
attach[K: Eq + Hash, V] Table[K, V]get_mut_by_hash[Q]mut self, h: u64, query: *Q, eq_fn: func(*K, *Q) -> boolMaybe[*mut V]
attach[K: Eq + Hash, V] Table[K, V]del_by_hash[Q]mut self, h: u64, query: *Q, eq_fn: func(*K, *Q) -> boolMaybe[V]
attach[K: Eq + Hash, V] Table[K, V]getin self, key: *KMaybe[*V]
attach[K: Eq + Hash, V] Table[K, V]get_mutmut self, key: *KMaybe[*mut V]
attach[K: Eq + Hash, V] Table[K, V]hasin self, key: *Kbool
attach[K: Eq + Hash, V] Table[K, V]delmut self, key: *KMaybe[V]
attach[K: Eq + Hash, V] Table[K, V]clearmut selfunit
attach[K: Eq + Hash, V] Table[K, V]iterin selfTableIter[K, V]
attach[K: Eq + Hash, V] Table[K, V] : Dropdropmut selfunit

Worked Example (kit.table)

stag
use kit.io (Console)
use kit.table (Table)
use kit.text (Text)

func main() -> i32:
    var scores = Table[Text, i64].new()
    _ := scores.set(Text.from_str("lexer"), 10)
    _ := scores.set(Text.from_str("sema"), 32)
    k := Text.from_str("sema")
    msg := f"len={scores.len()} sema={*scores.get(&k).unwrap()}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
len=2 sema=32

kit.text

Stag Standard Kit: owned, growable, NUL-terminated UTF-8 string (Text). Maintains a trailing NUL byte so as_cstr() is O(1) with zero allocation for C FFI.

Types, Traits & Constants

stag
pub record Text

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
Textnew*(none)*Text
Textwith_capcap: i64Text
Textfrom_strs: strText
Textfrom_cstrcstr: *u8Text
Textclonein selfText
Textlenin selfi64
Textcapin selfi64
Textis_emptyin selfbool
Textreservemut self, additional: i64unit
Textpush_bytemut self, b: u8unit
Textpush_rawmut self, ptr: *u8, len: i64unit
Textpush_repeatmut self, b: u8, count: i64unit
Textpush_strmut self, s: strunit
Textpush_u64mut self, val: u64unit
Textpush_i64mut self, val: i64unit
Textpush_f64mut self, val: f64unit
Textclearmut selfunit
Textas_strin selfstr
Textas_cstrin self*u8
Textas_bytesin self[]u8
Textbyte_atin self, idx: i64Maybe[u8]
Textsubstrin self, start: i64, end: i64Text
Texteq_strin self, s: strbool
Textstarts_within self, prefix: strbool
Textends_within self, suffix: strbool
Textfindin self, needle: strMaybe[i64]
Textcontainsin self, needle: strbool
Texttrim_startin selfText
Texttrim_endin selfText
Texttrimin selfText
Textto_upperin selfText
Textto_lowerin selfText
Textsplitin self, delim: u8List[Text]
Textreplace_strin self, from: str, to: strText
Textparse_u64in selfOutcome[u64, i32]
Textparse_i64in selfOutcome[i64, i32]
Text : Dropdropmut selfunit
Text : Eqeqin self, other: *Textbool
Text : Ordcmpin self, other: *Texti32
Text : Addaddin self, rhs: TextSelf.Output
Text : Hashhashin self, h: *mut Hasherunit

Worked Example (kit.text)

stag
use kit.io (Console)
use kit.text (Text)

func main() -> i32:
    raw := Text.from_str("  stag,llvm,kit  ").trim()
    parts := raw.split(44u8)
    n := Text.from_str("-42").parse_i64().unwrap()
    msg := f"parts={parts.len()} first={parts.get(0).unwrap().to_upper()} parsed={n}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
parts=3 first=STAG parsed=-42

kit.time

Stag Standard Kit: wall-clock timestamps, monotonic high-resolution clocks, duration helpers, stopwatch timer, and sleep utilities.

Types, Traits & Constants

stag
pub const NANOS_PER_MICRO: i64 = 1000
pub const NANOS_PER_MILLI: i64 = 1000000
pub const NANOS_PER_SECOND: i64 = 1000000000
pub const MICROS_PER_MILLI: i64 = 1000
pub const MICROS_PER_SECOND: i64 = 1000000
pub const MILLIS_PER_SECOND: i64 = 1000
pub record Duration
pub record Timer

Free Functions (Inputs & Outputs)

FunctionInput ParametersReturn Type
unix_seconds*(none)*i64
unix_millis*(none)*i64
unix_micros*(none)*i64
unix_nanos*(none)*i64
now_ms*(none)*i64
now_us*(none)*i64
now_ns*(none)*i64
diff_secondsend_ts: i64, start_ts: i64f64
monotonic_ns*(none)*i64
monotonic_us*(none)*i64
monotonic_ms*(none)*i64
monotonic_seconds*(none)*f64
sleep_nsns: i64unit
sleep_usus: i64unit
sleep_msms: i64unit
sleep_secondssec: i64unit

Attached Methods & Trait Implementations (Inputs & Outputs)

Receiver / Trait BlockMethodInput ParametersReturn Type
Durationzero*(none)*Duration
Durationfrom_nanosns: i64Duration
Durationfrom_microsus: i64Duration
Durationfrom_millisms: i64Duration
Durationfrom_secondssec: i64Duration
Durationas_nanosin selfi64
Durationas_microsin selfi64
Durationas_millisin selfi64
Durationas_millis_f64in selff64
Durationas_secondsin selff64
Durationis_zeroin selfbool
Durationaddin self, other: DurationDuration
Durationsubin self, other: DurationDuration
Timerstart*(none)*Timer
Timerelapsed_nsin selfi64
Timerelapsed_usin selfi64
Timerelapsed_msin selfi64
Timerelapsed_ms_f64in selff64
Timerelapsed_secondsin selff64
Timerelapsedin selfDuration
Timerlap_nsmut selfi64
Timerlap_msmut selfi64
Timerlapmut selfDuration
Timerresetmut selfunit

Worked Example (kit.time)

stag
use kit.io (Console)
use kit.time

func main() -> i32:
    t := time.Timer.start()
    time.sleep_ms(5)
    elapsed := t.elapsed_ms()
    epoch := time.unix_seconds()
    msg := f"elapsed_ge_4ms={elapsed >= 4} epoch_valid={epoch > 1700000000}"
    Console.println(msg.as_str())
    0i32

Expected Output:

text
elapsed_ge_4ms=true epoch_valid=true