Redesign String and Array APIs aligned with Rust#735
Merged
Conversation
Design proposal to unify String and Array APIs with consistent naming (push/extend/contains/find), add missing methods (split, join, reverse, insert, remove, etc.), and deprecate inconsistent append/append_char. https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
Restructure around Array↔Vec and String↔String/str mapping tables instead of String-vs-Array comparison. Add byte-index convention, pattern argument design, and per-type Rust method mapping. https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
Lazy iteration is more efficient and consistent with Rust's API. Users can .collect() when they need an Array<String>. https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
GC manages the internal buffer (repr), not the capacity of String/Array, so these methods are needed for users. https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
Array: add push (rename from append), first, clear, capacity, reserve, shrink_to_fit, insert, remove, swap, reverse, extend, contains, repeat, join, windows, chunks. Mark append as deprecated. String: add push_str (rename from append), push (rename from append_char), pop, clear, capacity, reserve, shrink_to_fit, as_bytes, contains, starts_with, ends_with, find, rfind, contains_char, find_char, truncate (rename from truncate_bytes), insert, insert_str, remove, repeat, replace, replacen, split, splitn, split_whitespace, lines, char_indices. Mark append/append_char/truncate_bytes as deprecated. Migrate all stdlib callers to use new API names. Add comprehensive tests for all new methods. All 4380 E2E tests and stdlib tests pass. https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
- Compiler: template.rs uses push_str instead of append for String - Compiler: cm_binding.rs uses push instead of append for Array - 80 test fixtures: Array.append → push, String.append → push_str - WIR patterns updated in inline_cross_module_method and array_append_collapse - docs/spec.md and docs/cheatsheet.md updated - Format fixtures updated - WASI Fields::append left unchanged (WIT-defined method) https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
Regenerated all WIR golden fixtures reflecting the push/push_str rename. Updated auto-generated stdlib docs (cheatsheet-stdlib-core.md, stdlib-core.md). All tests pass. https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StringandArray<T>APIs to align with Rust'sString/&strandVec<T>/&[T]APIs (excluding lifetime/ownership concepts)push(rename fromappend),first,clear,capacity,reserve,shrink_to_fit,insert,remove,swap,reverse,extend,contains,repeat,join,windows,chunkspush_str(rename fromappend),push(rename fromappend_char),pop,clear,capacity,reserve,shrink_to_fit,as_bytes,contains,starts_with,ends_with,find,rfind,contains_char,find_char,truncate(rename fromtruncate_bytes),insert,insert_str,remove,repeat,replace,replacen,split,splitn,split_whitespace,lines,char_indicesappend,append_char,truncate_bytes) marked as@deprecatedand kept as aliasesdocs/wep-2026-03-29-redesign-string-array-api.mdTest plan
on-task-donecompleted successfully (format, clippy, golden fixtures, stdlib docs)https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H