Skip to content

Commit 2a7152e

Browse files
authored
Merge pull request #735 from wado-lang/claude/align-api-design-jD1QI
Redesign String and Array APIs aligned with Rust
2 parents 5b8974c + 494be0d commit 2a7152e

File tree

640 files changed

+71278
-43617
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

640 files changed

+71278
-43617
lines changed

docs/AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,4 @@ It may include TODOs on WIP.
9393
- [WIT Bundling in Component Binaries](./wep-2026-03-21-wit-bundling.md)
9494
- [Same-Scope Shadowing with Self-Reference](./wep-2026-03-25-same-scope-shadowing.md)
9595
- [Migration to GC in Components](./wep-2026-03-28-gc-in-components.md)
96+
- [Redesign String and Array APIs](./wep-2026-03-29-redesign-string-array-api.md)

docs/cheatsheet-stdlib-core.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,13 +853,22 @@ impl String {
853853
pub fn internal_append_from_memory(&mut self, ptr: i32, len: i32);
854854
pub fn internal_reserve_uninit(&mut self, n: i32) -> i32;
855855
pub fn append_byte_filled(&mut self, byte: u8, n: i32);
856+
pub fn push_str(&mut self, other: String);
856857
pub fn append(&mut self, other: String);
857858
pub fn concat(a: String, b: String) -> String;
858859
pub fn bytes(&self) -> StrUtf8ByteIter;
859860
pub fn chars(&self) -> StrCharIter;
861+
pub fn push(&mut self, c: char);
860862
pub fn append_char(&mut self, c: char);
861-
pub fn truncate_bytes(&mut self, byte_len: i32);
863+
pub fn truncate(&mut self, byte_len: i32);
862864
pub fn truncate_chars(&mut self, char_count: i32);
865+
pub fn truncate_bytes(&mut self, byte_len: i32);
866+
pub fn pop(&mut self) -> Option<char>;
867+
pub fn clear(&mut self);
868+
pub fn capacity(&self) -> i32;
869+
pub fn reserve(&mut self, additional: i32);
870+
pub fn shrink_to_fit(&mut self);
871+
pub fn as_bytes(&self) -> Array<u8>;
863872
pub fn trim_ascii_start(&self) -> String;
864873
pub fn trim_ascii_end(&self) -> String;
865874
pub fn trim_ascii(&self) -> String;
@@ -868,10 +877,28 @@ impl String {
868877
pub fn trim(&self) -> String;
869878
pub fn to_ascii_lowercase(&self) -> String;
870879
pub fn to_ascii_uppercase(&self) -> String;
880+
pub fn contains(&self, pat: String) -> bool;
881+
pub fn starts_with(&self, pat: String) -> bool;
882+
pub fn ends_with(&self, pat: String) -> bool;
883+
pub fn find(&self, pat: String) -> Option<i32>;
884+
pub fn rfind(&self, pat: String) -> Option<i32>;
885+
pub fn contains_char(&self, ch: char) -> bool;
886+
pub fn find_char(&self, pred: Fn(char) -> bool) -> Option<i32>;
887+
pub fn insert(&mut self, byte_index: i32, ch: char);
888+
pub fn insert_str(&mut self, byte_index: i32, s: String);
889+
pub fn remove(&mut self, byte_index: i32) -> char;
890+
pub fn repeat(&self, n: i32) -> String;
891+
pub fn replace(&self, from: String, to: String) -> String;
892+
pub fn replacen(&self, from: String, to: String, count: i32) -> String;
871893
pub fn from_iter<I: IntoIterator<Item = char>>(iter: I) -> String;
872894
pub fn from_utf8<I: IntoIterator<Item = u8>>(bytes: I) -> Result<String, String>;
873895
pub fn from_utf8_lossy<I: IntoIterator<Item = u8>>(bytes: I) -> String;
874896
pub fn from_utf8_unchecked<I: IntoIterator<Item = u8>>(bytes: I) -> String;
897+
pub fn split(&self, sep: String) -> StrSplitIter;
898+
pub fn splitn(&self, n: i32, sep: String) -> StrSplitNIter;
899+
pub fn split_whitespace(&self) -> StrSplitWhitespaceIter;
900+
pub fn lines(&self) -> StrLinesIter;
901+
pub fn char_indices(&self) -> StrCharIndicesIter;
875902
}
876903
877904
impl Add for String {
@@ -1033,20 +1060,36 @@ impl Array {
10331060
pub fn filled(n: i32, element: T) -> Array<T>;
10341061
pub fn len(&self) -> i32;
10351062
pub fn is_empty(&self) -> bool;
1063+
pub fn capacity(&self) -> i32;
10361064
pub fn internal_raw_data(&self) -> builtin::array<T>;
10371065
pub fn internal_from_raw(repr: builtin::array<T>, used: i32) -> Array<T>;
1066+
pub fn push(&mut self, value: T);
10381067
pub fn append(&mut self, value: T);
10391068
pub fn pop(&mut self) -> Option<T>;
1040-
pub fn truncate(&mut self, len: i32);
1069+
pub fn first(&self) -> Option<T>;
10411070
pub fn last(&self) -> Option<T>;
10421071
pub fn get(&self, index: i32) -> Option<T>;
1072+
pub fn insert(&mut self, index: i32, value: T);
1073+
pub fn remove(&mut self, index: i32) -> T;
1074+
pub fn swap(&mut self, a: i32, b: i32);
1075+
pub fn truncate(&mut self, len: i32);
1076+
pub fn clear(&mut self);
1077+
pub fn reserve(&mut self, additional: i32);
1078+
pub fn shrink_to_fit(&mut self);
1079+
pub fn extend(&mut self, other: &Array<T>);
1080+
pub fn reverse(&mut self);
1081+
pub fn repeat(&self, n: i32) -> Array<T>;
10431082
pub fn copy_within_append(&mut self, src_start: i32, count: i32);
1083+
pub fn contains(&self, value: &T) -> bool;
10441084
pub fn slice(&self, start: i32, end: i32) -> ArraySlice<T>;
10451085
pub fn iter(&self) -> ArrayIter<T>;
10461086
pub fn sort_by(&mut self, cmp: Fn(&T, &T) -> Ordering);
10471087
pub fn sorted_by(&self, cmp: Fn(&T, &T) -> Ordering) -> Array<T>;
1088+
pub fn windows(&self, size: i32) -> WindowsIter<T>;
1089+
pub fn chunks(&self, size: i32) -> ChunksIter<T>;
10481090
pub fn sort(&mut self);
10491091
pub fn sorted(&self) -> Array<T>;
1092+
pub fn join(&self, separator: String) -> String;
10501093
}
10511094
10521095
impl IndexValue<i32> for Array<T> {

docs/cheatsheet.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ takes([1, 2, 3]); // coercion to Array
165165
166166
// Array methods
167167
let mut arr: Array<i32> = [];
168-
arr.append(1); // add element to end
168+
arr.push(1); // add element to end
169169
let n = arr.len(); // get length
170170
let empty = arr.is_empty(); // check if empty
171171
let first = arr[0]; // index access (read)
@@ -219,8 +219,8 @@ let empty = s.is_empty();
219219
220220
// String building
221221
let mut builder = String::with_capacity(20);
222-
builder.append("Hello");
223-
builder.append(", World!");
222+
builder.push_str("Hello");
223+
builder.push_str(", World!");
224224
225225
// Iterating over characters
226226
for let c of "hello".chars() {

docs/spec.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,9 @@ The `append` method provides efficient O(1) amortized string building:
11711171

11721172
```wado
11731173
let mut builder = String::with_capacity(20);
1174-
builder.append("Hello");
1175-
builder.append(", ");
1176-
builder.append("World!");
1174+
builder.push_str("Hello");
1175+
builder.push_str(", ");
1176+
builder.push_str("World!");
11771177
// builder is now "Hello, World!"
11781178
11791179
// Static method for two-string concatenation
@@ -1679,7 +1679,7 @@ arr[0] = 100; // Requires mutable array
16791679
arr[1] = 200;
16801680
16811681
// Array methods
1682-
arr.append(4); // Add element to end
1682+
arr.push(4); // Add element to end
16831683
let len = arr.len(); // Get length
16841684
```
16851685

@@ -3968,7 +3968,7 @@ The `stores[...]` keyword declares that a function stores reference parameters b
39683968
```wado
39693969
// Function that stores a reference parameter
39703970
fn register(data: &Data) -> Handle with stores[data] {
3971-
registry.append(data); // Stores the reference
3971+
registry.push(data); // Stores the reference
39723972
return new_handle();
39733973
}
39743974
@@ -4067,7 +4067,7 @@ fn collect_all() -> Array<i32> {
40674067
40684068
with handler Generator<i32> {
40694069
yield(value) => |resume| {
4070-
result.append(value);
4070+
result.push(value);
40714071
resume();
40724072
},
40734073
} {

0 commit comments

Comments
 (0)