StrBuf
struct · Source line 98
pub struct StrBuf { bytes: List[byte], }The builder: an owned, growable string. The field is the backing described in the module header (the contents' UTF-8 bytes) — never part of the API.
wolf-std d58f9e1
· toolchain pin verified against wolf 0.2.41 (0261597).
Source signatures and documentation; execution support is stated in each module.
All modules · Plain text · Stability tier: core
std.strbuf — the one string builder (D24). Stability tier: core.
What is the language's and what is std's. Nothing here is the language's yet: str is the language's immutable UTF-8 slice, and D24 promises strbuf as an owned, growable, SSO-backed builder that auto-borrows to str — compiler-side plumbing (s37 §3) that does not exist at this pin. This module is the API surface that plumbing will back, written today over the language's growable byte list.
**THE BACKING IS A List[byte] (sc75, wolf-std#108).** The bytes of the contents, UTF-8 by construction, in one list that grows by doubling. push_str pushes its argument's bytes onto the end, reading them through s.bytes()'s view ([mem.str.view.lend]: iterated on the spot, nothing materialized), so appending n bytes costs O(n) amortized whatever the buffer already holds, and to_str validates and copies the contents once. Until sc75 the field was a str rebuilt by +=: every push_str allocated a fresh string and copied the whole accumulator into it, and the region kept every copy until it ended, so a builder was quadratic in time AND in resident memory. #108 measured it on wolf 0.2.34: 4 MiB pushed in 64-byte lines took 30 s, 6 MiB reached 12.9 GB resident and 8 MiB was killed. The meaning of every function is unchanged, and so is every signature (R-sc75-1); only the costs moved, and each function's doc states its own. On the region ledger a pushed builder charges about twice its contents natively (the doubling's abandoned buffers, [mem.region.account.1]) and once on the checked machine; to_str charges the contents once more.
The SSO backing D24 names is still compiler-side plumbing, and when it lands no caller has to change (F-0019); this file is where the layout note for s41/s43's ABI document will hang.
StrBuf is CapCase per API-CONVENTIONS §1 even though the sprint contract writes the constructor as strbuf(): a callable type name is s37's builtin spelling, and strbuf.new() is the module spelling available today. That delta is recorded in the campaign closeout.
TWO OF THE ELEVEN ARE NOT HERE, each for a stated reason — and push(c: char) LEFT this list at sc24: D58 ruled the type ([type.char], the sc24 data pin) and the sc24 wolf pair executes it, so the one-line body ({c} interpolation, which prints THE CHARACTER per [type.char.interp]) is code below — on every executing lane as of sc25: lupin 0.1.15 (is26, the scalar release) runs char, and the row that sc24 ledgered by lane flipped at that release as promised. The sc24 history stays worth a sentence: the sprint's first wolf acquisition (@ e7abf03) was pre-s121 and refused the type — the mid-sprint re-acquisition is what made this writable, and every sentence here was re-measured against the binary pinned.
- strbuf.in(r) — the region-explicit constructor (API-CONVENTIONS §5, the s37 .in(r) pattern). Placement syntax over a std type is compiler plumbing this pin does not have; the ambient-region constructor below is D10's default and needs no annotation. RE-PROBED rather than argued at the sc32 pin v0.2.2/8cda3aa (2026-09-02), because for the first time in this residue's life the span MOVED regions for real — s131 and s132 landed the byte ledger, the creation-time cap and D68's contained fault whole-pipe, so "regions did not change" stopped being a sentence a reader should take on trust. The probe is the placement syntax itself, both shapes: List[int].in(r) is unsupported — a std/prelude stub without a signature at resolve on both wolf rungs AND refused by lupin, and Buf.in(r) { … } over a plain struct is fail(E0201) at PARSE on all three — the form does not exist in the grammar, which is the honest state of a surface nobody has built. s131/s132 gave regions an ACCOUNTING surface and a BUDGET; they gave them no placement plumbing, and the two are different work. std.mem.budget is what this repo consumed from that span instead. - reserve(n) — API-CONVENTIONS §8's rule ("no capacity API without a capacity") kept it out while the buffer was a str, which has no capacity to reserve. sc75: the capacity now exists — the list under the builder has the language's reserve(n) ([type.list.storage]) — and §8's builder amendment (R-sc75-1) says what that changes: the rule's reason is gone, the name is not added in the same pass that moves the backing, because the public API stays exactly as it was (a caller adding reserve is a later lane's API change, asked as a ruling). The history this bullet carried: UNMOVED at the sc32 pin (2026-09-02): there is no capacity or string-backing commit anywhere in 75fd2d0..8cda3aa or 0.1.20..0.1.22. And the question this line carried forward from sc31 is now ANSWERED rather than deferred — the region accounting surface wolf-lang#187 asked for landed in this span (both halves: region_bytes/ live_region_bytes from s131, the cap: budget and its contained fault(kind) from s132/D68), it was consumed at sc32, and it lives in std.mem.budget. It bought this module nothing, which is the honest outcome: a ledger tells you what a buffer COST and a cap tells you when to stop, and neither is a capacity you can reserve.
Absence is spelled none where it appears, which is the convention's own spelling: F-0003 died at the sc05 pins and the rename landed tree-wide at sc06, so nothing here is waiting on it.
struct · Source line 98
pub struct StrBuf { bytes: List[byte], }The builder: an owned, growable string. The field is the backing described in the module header (the contents' UTF-8 bytes) — never part of the API.
fn · Source line 109
pub fn new() -> StrBufA fresh empty builder in the ambient region (D10: no region argument, no annotation). Total: no error row, no traps.
let b = strbuf.new()
strbuf.len(b) == 0fn · Source line 122
pub fn len(b: StrBuf) -> intThe length of the buffer's contents in BYTES — the same honest unit as str.len (D25: byte offsets are the one currency). O(1). Total: no error row, no traps.
var b = strbuf.new()
strbuf.push_str(mut b, "é")
strbuf.len(b) == 2fn · Source line 150
pub fn push_str(mut b: StrBuf, s: str)Appends s to the end of the buffer. Amortized O(len(s)), whatever the buffer already holds: the bytes are pushed onto the backing list, read through s.bytes()'s view, so nothing is copied but s itself (sc75, wolf-std#108; until then O(len(b) + len(s)), the whole accumulator copied every call). Total: no error row, no traps beyond allocation.
The += spelling the sprint contract mentions — b += s on the BUFFER — is not available: the operator-to-method bridge is F-0004's open question, and wolf has no operator overloading, so a StrBuf cannot be the left side of one. push_str is the one spelling std writes. (The sentence that stood here until sc43 went on to say + on str "runs in lupin and is E0409 in wolfc". That was true when it was written and stopped being true at D62, which this very body adopted: b.s += s was a str += on all three lanes, and sc43's push was its char twin one function down. sc75 retired both bodies for the byte list; the operator story above is unchanged.)
var b = strbuf.new()
strbuf.push_str(mut b, "wolf")
strbuf.push_str(mut b, "-lang")
strbuf.to_str(b) == "wolf-lang"fn · Source line 195
pub fn push(mut b: StrBuf, c: char)Appends one code point — the sc03 contract's push(c), code at last (sc24), over D58's char ([type.char]: a Unicode scalar value, ordered, NOT an integer). The appended bytes are exactly c's UTF-8 encoding, 1 to 4 of them, computed from the scalar's value by the width rule [mem.str.chars] states (1 byte under 0x80, 2 under 0x800, 3 under 0x10000, else 4), so the buffer's UTF-8 validity is preserved by construction: a non-scalar cannot exist as a char at all (the D56 cast already trapped it). Amortized O(1) (sc75; until then O(len(b)), the accumulator copied as in push_str). Total: no error row, no traps beyond allocation.
**sc75: the body encodes instead of appending a str.** Until sc75 it was b.s += c, which [type.str.concat] rules to append THE CHARACTER; over the byte list the same bytes are pushed directly, so a push allocates nothing of its own.
It was an interpolation hole until sc43 — b.s = "{b.s}{c}" — and the hole existed for exactly one reason: + refused a char, so the only way to put one on the end of a str was to render it into a new string. wolf-lang#278 admitted a char on either side of + and as the value of += at v0.2.9, and lupin 0.1.31 mirrored it (is43, wolf-interp#78). From sc43 to sc75 the two appenders were written in one idiom, b.s += s and b.s += c, with [type.str.concat] carrying the character across; since sc75 each pushes bytes, push_str a str's through its view and this one a scalar's by the width rule.
LANES: every executing lane runs this as of the sc25 pins — both wolf rungs since s121, lupin since 0.1.15 (is26, the scalar release; sc24's one-sprint unsupported there closed on it). The example keeps its "é🐺".chars() spelling because the walk is the natural producer here, not as the lex-dodge it was under 0.1.14.
var b = strbuf.new()
for c in "é🐺".chars() { strbuf.push(mut b, c) }
strbuf.to_str(b) == "é🐺"
strbuf.len(b) == 6fn · Source line 234
pub fn insert(mut b: StrBuf, off: int, s: str)Inserts s at byte offset off, shifting everything at or after off to the right. off == len(b) appends; off == 0 prepends.
Traps bounds ([conf.trap.set]) when off is out of range or falls inside a code point — the language's own checked slicing (D25), raised exactly where a caller would see it. That is the "checked boundary" the contract asks for; the recoverable form — an insert that raises rather than traps — is writable over str.get as of s37 (sc09) and is a std.strbuf sprint's to add, under its own name, beside this one.
O(len(b) + len(s)): the contents are read as a str once, sliced at off (where the trap comes from), and the buffer is refilled in its own storage (reset, [type.list.reset]).
var b = strbuf.new()
strbuf.push_str(mut b, "wolf")
strbuf.insert(mut b, 0, "the ")
strbuf.to_str(b) == "the wolf"fn · Source line 263
pub fn remove(mut b: StrBuf, from: int, to: int)Removes the bytes in [from, to), closing the gap. Empty when from == to.
Traps bounds when the range is out of order, out of range, or splits a code point (D25, as insert). The contract writes this as remove(a..b); a range is not a value that can cross a function boundary at this pin (fn f(r: Range) is E0301 in wolfc), so the two offsets are spelled as two parameters — the same interim str.get carries, flipping together with it.
O(len(b)), as insert: the contents read as a str once, sliced, and the buffer refilled in its own storage.
var b = strbuf.new()
strbuf.push_str(mut b, "the wolf")
strbuf.remove(mut b, 0, 4)
strbuf.to_str(b) == "wolf"fn · Source line 290
pub fn truncate(mut b: StrBuf, n: int)Shortens the buffer to n bytes, dropping everything after. Keeps the buffer usable and is a no-op when n == len(b).
Traps bounds when n exceeds the length or splits a code point (D25) — truncation is exactly a checked slice.
O(len(b) - n) when n is a boundary: the bytes past it are popped off the backing list, which keeps its storage. A length that is not a boundary — negative, past the end, or on a UTF-8 continuation byte — is handed to the language's checked slice of the contents, which raises the trap exactly as s[..n] does.
var b = strbuf.new()
strbuf.push_str(mut b, "wolf-lang")
strbuf.truncate(mut b, 4)
strbuf.to_str(b) == "wolf"fn · Source line 315
pub fn clear(mut b: StrBuf)Empties the buffer, keeping it usable. Total: no error row, no traps.
var b = strbuf.new()
strbuf.push_str(mut b, "wolf")
strbuf.clear(mut b)
strbuf.len(b) == 0fn · Source line 336
pub fn to_str(b: StrBuf) -> strThe buffer's contents as a str. A borrow of the buffer's bytes under D24's auto-borrow story — as_/bare-noun territory in API-CONVENTIONS §1 rather than an allocating to_. The name is the contract's. Over the byte list the value is a COPY, made once: O(len(b)), the bytes validated and copied into a fresh str in the ambient region (str_from_utf8), and the builder stays usable. Read it once, at the end of a build, not once per push. Total: no error row, no traps — the contents are UTF-8 by construction (every append is a str's bytes or a scalar's encoding, and every cut is checked at a code-point boundary), so the decoder's utf8 row cannot arise; were it ever to, to_str traps assert rather than answer wrong text.
var b = strbuf.new()
strbuf.push_str(mut b, "wolf")
strbuf.to_str(b) == "wolf"No public declarations in this section.
No public declarations in this section.