Files
bux-lang/docs/api/stdlib.md
T
dimgigov 53b43b0f79 feat: lifetime elision, tooling CI, registry, and LSP locals
Ship the QUALITY_PLAN stretch from ownership through ecosystem: C.1
lifetime elision (bootstrap + selfhost), bux fmt/test/doc CI hooks,
stdlib goldens, package registry (bux search/add), and LSP 0.4
position-sensitive locals with inferred let types. Full-tree format
pass plus Map/Set remove double-free fix.
2026-07-19 16:35:08 +03:00

750 lines
11 KiB
Markdown

# API Reference
Generated by `bux doc` from `///` and `/* */` documentation comments.
## `Array`
_Source: `lib/Array.bux`_
### `Array` _struct_
```bux
struct Array<T> {
```
Growable contiguous buffer of `T` (len + capacity).
### `Array_New` _func_
```bux
func Array_New<T>(cap: uint) -> Array<T> {
```
Create an empty array with the given initial capacity.
### `Array_Push` _func_
```bux
func Array_Push<T>(self: *Array<T>, value: T) {
```
Append `value`, growing capacity if needed.
### `Array_Get` _func_
```bux
func Array_Get<T>(self: *Array<T>, index: uint) -> T {
```
Element at `index` (bounds-checked unless `@[Release]`).
### `Array_Set` _func_
```bux
func Array_Set<T>(self: *Array<T>, index: uint, value: T) {
```
Write `value` at `index` (bounds-checked unless `@[Release]`).
### `Array_Len` _func_
```bux
func Array_Len<T>(self: *Array<T>) -> uint {
```
Number of live elements.
### `Array_Free` _func_
```bux
func Array_Free<T>(self: *Array<T>) {
```
Free the backing buffer and reset length/capacity to zero.
### `Array_Drop` _func_
```bux
func Array_Drop<T>(self: *Array<T>) {
```
Drop trait entry — same as `Array_Free`.
### `Array_IsEmpty` _func_
```bux
func Array_IsEmpty<T>(self: *Array<T>) -> bool {
```
True if the array has no elements.
### `Array_Cap` _func_
```bux
func Array_Cap<T>(self: *Array<T>) -> uint {
```
Current capacity (not length).
### `Array_Clear` _func_
```bux
func Array_Clear<T>(self: *Array<T>) {
```
Drop length to zero; keeps allocated capacity.
### `Array_Reserve` _func_
```bux
func Array_Reserve<T>(self: *Array<T>, minCap: uint) {
```
Ensure capacity is at least `minCap` (does not shrink).
### `Array_First` _func_
```bux
func Array_First<T>(self: *Array<T>) -> T {
```
First element (bounds-checked if empty).
### `Array_Last` _func_
```bux
func Array_Last<T>(self: *Array<T>) -> T {
```
Last element (bounds-checked if empty).
### `Array_Pop` _func_
```bux
func Array_Pop<T>(self: *Array<T>) -> T {
```
Remove and return the last element (bounds-checked if empty).
### `Array_Contains` _func_
```bux
func Array_Contains<T>(self: *Array<T>, value: T) -> bool {
```
Linear search: true if `value` is present (uses `==`).
### `Array_IndexOf` _func_
```bux
func Array_IndexOf<T>(self: *Array<T>, value: T) -> int {
```
Index of first equal element, or `-1` if not found.
### `Array_Extend` _func_
```bux
func Array_Extend<T>(self: *Array<T>, other: *Array<T>) {
```
Append all elements of `other` onto `self`.
## `Channel`
_Source: `lib/Channel.bux`_
### `Channel_SendInt` _func_
```bux
func Channel_SendInt(ch: *Channel<int>, value: int) {
```
Convenience wrappers for common types
## `Iter`
_Source: `lib/Iter.bux`_
### `Array_Iter` _func_
```bux
func Array_Iter<T>(arr: *Array<T>) -> Iter<T> {
```
Create an iterator from an Array
### `Iter_HasNext` _func_
```bux
func Iter_HasNext<T>(it: *Iter<T>) -> bool {
```
Check if there are more elements
### `Iter_Next` _func_
```bux
func Iter_Next<T>(it: *Iter<T>) -> T {
```
Get the next element and advance (undefined if HasNext is false)
### `Iter_Peek` _func_
```bux
func Iter_Peek<T>(it: *Iter<T>) -> T {
```
Peek current element without advancing (undefined if HasNext is false)
### `Iter_Reset` _func_
```bux
func Iter_Reset<T>(it: *Iter<T>) {
```
Reset iterator to the beginning
### `Iter_Pos` _func_
```bux
func Iter_Pos<T>(it: *Iter<T>) -> uint {
```
Current position
### `Iter_Len` _func_
```bux
func Iter_Len<T>(it: *Iter<T>) -> uint {
```
Remaining length
### `Iter_Count` _func_
```bux
func Iter_Count<T>(it: *Iter<T>) -> uint {
```
Count remaining elements
### `Iter_Skip` _func_
```bux
func Iter_Skip<T>(it: *Iter<T>, n: uint) {
```
Skip N elements
### `Iter_Take` _func_
```bux
func Iter_Take<T>(it: *Iter<T>, n: uint) -> Iter<T> {
```
Take first N elements (by limiting len)
### `Iter_AnyEq` _func_
```bux
func Iter_AnyEq<T>(it: *Iter<T>, value: T) -> bool {
```
True if any remaining element equals value
### `Iter_AllEq` _func_
```bux
func Iter_AllEq<T>(it: *Iter<T>, value: T) -> bool {
```
True if every remaining element equals value (true if empty)
### `Iter_Collect` _func_
```bux
func Iter_Collect<T>(it: *Iter<T>) -> Array<T> {
```
Collect remaining elements into a new Array
### `Iter_Map` _func_
```bux
func Iter_Map<T, U>(it: *Iter<T>, f: func(T) -> U) -> Array<U> {
```
Map each remaining element through f: T → U, collect into Array<U>
### `Iter_Filter` _func_
```bux
func Iter_Filter<T>(it: *Iter<T>, pred: func(T) -> bool) -> Array<T> {
```
Keep remaining elements for which pred returns true
### `Iter_Fold` _func_
```bux
func Iter_Fold<T, Acc>(it: *Iter<T>, init: Acc, f: func(Acc, T) -> Acc) -> Acc {
```
Left-fold: f(f(...f(init, x0), x1), ...)
### `Iter_ForEach` _func_
```bux
func Iter_ForEach<T>(it: *Iter<T>, f: func(T) -> int) {
```
Call f for each remaining element (return value of f is ignored)
### `Iter_Any` _func_
```bux
func Iter_Any<T>(it: *Iter<T>, pred: func(T) -> bool) -> bool {
```
True if any remaining element satisfies pred
### `Iter_All` _func_
```bux
func Iter_All<T>(it: *Iter<T>, pred: func(T) -> bool) -> bool {
```
True if all remaining elements satisfy pred (true if empty)
### `Iter_SumInt` _func_
```bux
func Iter_SumInt(it: *Iter<int>) -> int {
```
Sum remaining ints (specialized fold)
## `Json`
_Source: `lib/Json.bux`_
### `JsonValue` _struct_
```bux
struct JsonValue {
```
=== Core type ===
### `Json_Null` _func_
```bux
func Json_Null() -> JsonValue {
```
=== Constructors ===
### `Json_ArrayLen` _func_
```bux
func Json_ArrayLen(v: JsonValue) -> uint {
```
=== Array helpers ===
### `Json_ObjectLen` _func_
```bux
func Json_ObjectLen(v: JsonValue) -> uint {
```
=== Object helpers ===
### `Json_IsNull` _func_
```bux
func Json_IsNull(v: JsonValue) -> bool {
```
=== Accessors ===
### `JsonParser` _struct_
```bux
struct JsonParser {
```
=== Parser ===
### `Json_Parse` _func_
```bux
func Json_Parse(s: String) -> JsonValue {
```
=== Public parser ===
### `Json_StringifyImpl` _func_
```bux
func Json_StringifyImpl(sb: *StringBuilder, v: JsonValue) {
```
=== Serializer ===
## `Map`
_Source: `lib/Map.bux`_
### `Map_Remove` _func_
```bux
func Map_Remove<K, V>(m: *Map<K, V>, key: K) -> bool {
```
Remove key if present. Rebuilds the table to keep open-addressing correct.
## `Net`
_Source: `lib/Net.bux`_
### `Net_Create` _func_
```bux
func Net_Create() -> int {
```
Create a TCP socket. Returns -1 on error.
### `Net_SetReuse` _func_
```bux
func Net_SetReuse(fd: int) -> bool {
```
Enable SO_REUSEADDR on a socket.
### `Net_Bind` _func_
```bux
func Net_Bind(fd: int, addr: String, port: int) -> bool {
```
Bind a socket to an address and port.
### `Net_Listen` _func_
```bux
func Net_Listen(fd: int, backlog: int) -> bool {
```
Start listening for connections.
### `Net_Accept` _func_
```bux
func Net_Accept(fd: int) -> int {
```
Accept a connection. Returns new fd or -1 on error.
### `Net_Connect` _func_
```bux
func Net_Connect(fd: int, addr: String, port: int) -> bool {
```
Connect to a remote address and port.
### `Net_Send` _func_
```bux
func Net_Send(fd: int, data: String) -> int {
```
Send data. Returns bytes sent or -1 on error.
### `Net_Recv` _func_
```bux
func Net_Recv(fd: int, maxLen: int) -> String {
```
Receive up to maxLen bytes. Returns empty string on error/EOF.
### `Net_Close` _func_
```bux
func Net_Close(fd: int) -> bool {
```
Close a socket.
### `Net_LastError` _func_
```bux
func Net_LastError() -> String {
```
Get last socket error as a string.
## `Option`
_Source: `lib/Option.bux`_
### `Option_Expect` _func_
```bux
func Option_Expect(o: Option, msg: String) -> int {
```
Unwrap Some or panic with a custom message
### `Option_Or` _func_
```bux
func Option_Or(o: Option, other: Option) -> Option {
```
If o is Some return it, otherwise return other
## `Os`
_Source: `lib/Os.bux`_
### `Os_Exit` _func_
```bux
func Os_Exit(code: int) {
```
Terminate the process with the given exit code
## `Result`
_Source: `lib/Result.bux`_
### `Result_Expect` _func_
```bux
func Result_Expect(r: Result, msg: String) -> int {
```
Unwrap Ok or panic with a custom message
### `Result_UnwrapErr` _func_
```bux
func Result_UnwrapErr(r: Result) -> String {
```
Extract Err payload (panics if Ok)
### `Result_Or` _func_
```bux
func Result_Or(r: Result, other: Result) -> Result {
```
If r is Ok return it, otherwise return other
## `Set`
_Source: `lib/Set.bux`_
### `Set_Remove` _func_
```bux
func Set_Remove<T>(s: *Set<T>, value: T) -> bool {
```
Remove value if present. Rebuilds the table to keep open-addressing correct.
## `String`
_Source: `lib/String.bux`_
### `String_Len` _func_
```bux
func String_Len(s: String) -> uint {
```
Byte length of a C string (`strlen`).
### `String_IsEmpty` _func_
```bux
func String_IsEmpty(s: String) -> bool {
```
True if the string has zero length.
### `String_IsNull` _func_
```bux
func String_IsNull(s: String) -> bool {
```
True if the pointer is null.
### `String_Eq` _func_
```bux
func String_Eq(a: String, b: String) -> bool {
```
Lexicographic equality.
### `String_Concat` _func_
```bux
func String_Concat(a: String, b: String) -> String {
```
Allocate and return `a` concatenated with `b`.
### `String_Copy` _func_
```bux
func String_Copy(s: String) -> String {
```
Heap-copy of `s`.
### `String_StartsWith` _func_
```bux
func String_StartsWith(s: String, prefix: String) -> bool {
```
True if `s` begins with `prefix`.
### `String_EndsWith` _func_
```bux
func String_EndsWith(s: String, suffix: String) -> bool {
```
True if `s` ends with `suffix`.
### `String_Contains` _func_
```bux
func String_Contains(s: String, substr: String) -> bool {
```
True if `substr` occurs anywhere in `s`.
### `String_IsBlank` _func_
```bux
func String_IsBlank(s: String) -> bool {
```
True if empty or only whitespace (space, tab, CR, LF).
### `String_Repeat` _func_
```bux
func String_Repeat(s: String, count: uint) -> String {
```
Repeat `s`, `count` times (`count == 0` → empty string).
### `String_ReplaceAll` _func_
```bux
func String_ReplaceAll(s: String, old: String, new: String) -> String {
```
Replace every non-overlapping occurrence of `old` with `new`.
Empty `old` is a no-op (returns `s` unchanged). Safe if `new` contains `old`.
## `Test`
_Source: `lib/Test.bux`_
### `Test_Exit` _func_
```bux
func Test_Exit(code: int) {
```
Exit the process with `code` (for test runners).
### `Test_Assert` _func_
```bux
func Test_Assert(cond: bool) {
```
Assert `cond` is true; abort on failure.
### `Test_AssertEqInt` _func_
```bux
func Test_AssertEqInt(a: int, b: int) {
```
Assert two ints are equal; print both values and exit 1 on mismatch.
### `Test_AssertNeqInt` _func_
```bux
func Test_AssertNeqInt(a: int, b: int) {
```
Assert two ints differ.
### `Test_AssertEqString` _func_
```bux
func Test_AssertEqString(a: String, b: String) {
```
Assert two strings are equal (`String_Eq`).
### `Test_AssertEqBool` _func_
```bux
func Test_AssertEqBool(a: bool, b: bool) {
```
Assert two bools are equal.
### `Test_AssertTrue` _func_
```bux
func Test_AssertTrue(cond: bool) {
```
Assert `cond` is true.
### `Test_AssertFalse` _func_
```bux
func Test_AssertFalse(cond: bool) {
```
Assert `cond` is false.
### `Test_Fail` _func_
```bux
func Test_Fail(msg: String) {
```
Fail the test with a message and exit 1.
### `Test_Pass` _func_
```bux
func Test_Pass(msg: String) {
```
Print a PASS line (for human-readable runners / goldens).