OwnedString API Reference

Owned heap-allocated string with length tracking and lifecycle management

Import

U std/owned_string

Struct

S OwnedString { data: i64, len: i64, cap: i64 }

Methods

MethodSignatureDescription
with_capacityF with_capacity(capacity: i64) -> OwnedStringCreate empty with capacity
from_strF from_str(s: i64) -> OwnedStringCopy from C string
lenF len(&self) -> i64Get length
capacityF capacity(&self) -> i64Get capacity
is_emptyF is_empty(&self) -> i64Check if empty
as_ptrF as_ptr(&self) -> i64Get raw pointer
char_atF char_at(&self, index: i64) -> i64Get character at index (ASCII)
push_charF push_char(&self, c: i64) -> i64Append character
push_strF push_str(&self, s: i64) -> i64Append C string
ensure_capacityF ensure_capacity(&self, needed: i64) -> i64Ensure at least needed bytes
growF grow(&self) -> i64Double capacity
eqF eq(&self, other: OwnedString) -> i64Compare with another OwnedString
eq_strF eq_str(&self, s: i64) -> i64Compare with C string
cloneF clone(&self) -> OwnedStringDeep copy
clearF clear(&self) -> i64Clear contents
printF print(&self) -> i64Print the string
dropF drop(&self) -> i64Free memory

Free Functions

FunctionSignatureDescription
owned_str_memcmpF owned_str_memcmp(a: i64, b: i64, len: i64) -> i64Compare bytes (1 if equal, 0 if not)
owned_str_concatF owned_str_concat(a: OwnedString, b: OwnedString) -> OwnedStringConcatenate two strings
owned_strF owned_str(s: i64) -> OwnedStringConvenience wrapper for from_str

Overview

Similar to String but designed for use in database engines and internal APIs where string ownership tracking is important. Automatically manages its buffer and supports safe conversion to/from raw i8* pointers.

Usage

U std/owned_string

F main() -> i64 {
    s := OwnedString.from_str("Hello")
    s.push_str(", World!")

    # Comparison
    s2 := OwnedString.from_str("Hello, World!")
    I s.eq(s2) {
        s.print()
    }

    # Clone
    s3 := s.clone()

    s.drop()
    s2.drop()
    s3.drop()
    0
}