This library is in flux. APIs may change without notice. Generated from source on 3/14/2026.
Formatting
Zero-overhead string formatting with Liquid-style templates.
fmt.kz
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
// ============================================================================
// FMT.DEALLOC - Discharge the [allocated!] obligation
// ============================================================================
~pub event fmt.dealloc {
formatted: *FormattedText[!allocated]
}
| done// ============================================================================
// FMT.BLK - Format with hidden default allocator (page_allocator)
// ============================================================================
//
// Syntax:
// fmt.blk {
// Hello {{ name:s }}!
// Count: {{ count:d }}
// }
// | formatted f |> ... use f.text ...
//
// The FormattedText carries its allocator, so fmt.dealloc knows how to free.
// Auto-discharge inserts fmt.dealloc automatically.
~[comptime|transform]pub event fmt.blk {
source: Source,
invocation: *const Invocation,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
}
| formatted *FormattedText[allocated!]~[norun]pub event fmt.blk.impl {
text: []const u8,
}// ============================================================================
// FMT.BLK.WITH_ALLOCATOR - Explicit allocator control
// ============================================================================
//
// For when you need a specific allocator (arena, etc.)
//
// Syntax:
// fmt.blk.with_allocator(allocator: my_arena) {
// Hello {{ name:s }}!
// }
// | formatted f |> ...
//
// 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 }}")
// | line 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 event ln {
invocation: *const Invocation,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
}
| transformed { program: *const Program }~[norun]pub event ln.impl {
expr: []const u8,
}
| line { text: []const u8 }