This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
Fmt
~import std/fmtKoru Standard Library: String Formatting
fmt.kz · 5 tors · ~[comptime]· ~[runtime]
Koru Standard Library: String Formatting
Zero-overhead string formatting with Liquid-style templates.
Returns allocated strings with phantom obligation tracking.
DESIGN: "Hidden but overridable"
- fmt.blk: Uses page_allocator internally, user never thinks about it
- fmt.blk.with_allocator: Explicit control when needed
- Auto-discharge handles cleanup via phantom obligations
Phantom lifecycles
Derived from the phantom labels in the declarations below — state! issues an
obligation the compiler will chase, !state discharges it, a bare state holds it without moving it. Nothing here is hand-drawn.
FormattedText 1 state string 1 state allocated!// FMT.DEALLOC - Discharge the <allocated!> obligation
~pub tor fmt.dealloc { formatted: *FormattedText<!allocated> }// The transform event returns SiteResult (the rewritten site) — the single-return
// form every `[transform]` decl lands as (frag-single-return-form-is-universal;
// `ln` is the twin). The RUNTIME value is the allocated string; a caller binds
// it with `: name` (`f` above), and legacy `| branch` sites get the `.formatted`
// union the inline_body breaks with. The `<allocated!>` obligation rides that
// runtime value, not the transform event's own return.
~[comptime|transform] pub tor fmt.blk {
source: Source,
invocation: *const Invocation,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
} -> SiteResult~[norun] pub tor fmt.blk.impl { text: string } -> string<std.io:allocated!>// TODO: fmt.blk.with_allocator - requires solving how user params
// coexist with transform infrastructure params in the pass runner.
// [comptime|transform]pub event fmt.blk.with_allocator { ... }
//
// FMT.LN - One-line format with Liquid templates, returns text via continuation
//
// Syntax:
// std/fmt:ln("Hello {{ name:s }}! Count: {{ count:d }}")
// : l |> ... use l.text ...
//
// Zero allocation: uses a thread-local buffer (safe across workers).
// The {{ var:spec }} placeholders are resolved at compile time into
// std.fmt.bufPrint calls that run at runtime in the caller's scope.
~[comptime|transform] pub tor ln {
invocation: *const Invocation,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
} -> SiteResult~[norun] pub tor ln.impl { expr: string } -> string