This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.

String

import std/string

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

string.kz · 20 tors· 1 internal

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. Parts: `~part owning` (hand-offs: copy/move out); `~part compare` (`contains`, `index-of`, `cmp`); `~part read` (lend bytes unqualified).

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.

String 2 states view!instance!

string carries the labels <*@scoped>, <*> with no obligation attached — a dimension, not a lifecycle.

new

<*@scoped><view!> koru_std/string.kz:36

from-page

<*@scoped><view!> koru_std/string.kz:55

take

<!view><instance!> koru_std/string.kz:79

release

<!instance><view!> koru_std/string.kz:83

free

<!view|!instance> koru_std/string.kz:94

len

<view|instance> koru_std/string.kz:101

from-int

<view!> koru_std/string.kz:128

substring

<view|instance><view!> koru_std/string.kz:147

append

<instance><*@scoped> koru_std/string.kz:208

append-char

<instance> koru_std/string.kz:225

pop-char

<instance> koru_std/string.kz:255

clear

<instance> koru_std/string.kz:269

~part owning koru_std/string.owning.kz

Koru Standard Library: the `owning` part of string.kz. Joined via `~part owning` in string.kz; merged into the module at load. The two ownership hand-offs — lifted for the line wall. `snapshot` copies out (the String keeps living); `detach` moves out (the String ends and the slice's ownership transfers to the caller). Snapshot - the escape path (610_007, ruled 2026-09-05) `read` (`{ s } -> string` via `-> s.data`) retired here: a returned borrow is unpoliceable — the owner can invalidate it by discharge OR mutation — so borrows flow down, never up (KORU095 refuses the projection). Consumers that used `read` to feed a call take the handle instead (borrow-for-the- call, `{{ h:S }}`); genuine escapes copy out through this tor. The copy carries `<view!>` so it cannot leak the way a bare allocating `string` return would. One memcpy, at a boundary, priced as noise.

snapshot

<view|instance><view!> koru_std/string.owning.kz:19

detach

<!view|!instance> koru_std/string.owning.kz:33

~part compare koru_std/string.compare.kz

Koru Standard Library: the `compare` part of string.kz. Joined via `~part compare` in string.kz; merged into the module at load. Predicates — substring containment Does the string contain `needle`?

contains

<view|instance> koru_std/string.compare.kz:9

index-of

<view|instance> koru_std/string.compare.kz:21

~part read koru_std/string.read.kz

Koru Standard Library: the `read` part of string.kz. Joined via `~part read` in string.kz; merged into the module at load. `read` retired as `-> s.data` because a returned borrow is unpoliceable: the owner can still discharge or mutate the buffer the borrow points into (KORU095 — borrows flow down, never up). It returns here in the policeable direction: `! text` lends `s.data` to the arm as an unqualified `string` for the call's duration — `for`, `split`, `parse-int` all take it — with no copy (`snapshot`) and no ownership move (`detach`, whose unlabeled owned slice no Koru leaf can dispose: its contract is a custody hand-off to HOST machinery, `body_allocated`'s post-send free — reaching for it to *read* produced text writes the leak the runtime counter catches). This is the produced-text exit the fmt.blk + `split("")` bridge was standing in for (820_008, gap-detach): `*String -> string` in one hop, `for`-acceptable.

read

<view|instance> koru_std/string.read.kz:16