This library is in flux. APIs may change without notice. Generated from source on 3/14/2026.

String

$std/string - String library with view/instance ownership model

string.kz

$std/string - String library with view/instance ownership model Ownership states: [view!] - read-only access, can be promoted to instance [instance!] - full control, can read/write/free The String struct carries its allocator, so it can be freed anywhere.
// ============================================
// Creation events - different allocator sources
// ============================================
// 
// Create with explicit allocator
~pub event new {
    allocator: std.mem.Allocator, text: []const u8
}
| ok { s: *String[view!] }
| err []const u8
// Create with page allocator (simple, for demos)
~pub event from_page {
    text: []const u8
}
| ok { s: *String[view!] }
| err []const u8
// ============================================
// Ownership transitions
// ============================================
// 
// Take ownership - view becomes instance
~pub event take {
    s: *String[!view]
}
| instance *String[instance!]
// Release ownership - instance becomes view
~pub event release {
    s: *String[!instance]
}
| view *String[view!]
// ============================================
// Cleanup
// ============================================
// 
// Free - works on either view or instance
~pub event free {
    s: *String[!view|instance]
}
// ============================================
// Read operations - work on view or instance
// ============================================
~pub event read {
    s: *String[view|instance]
}
| slice []const u8
~pub event len {
    s: *String[view|instance]
}
| len usize
// ============================================
// Write operations - require instance
// ============================================
~pub event append {
    s: *String[instance], text: []const u8
}
| ok
| err []const u8
~pub event clear {
    s: *String[instance]
}