Standard Library: String

std.string is a UTF-8 String with the same heap-record shape as std.vec, but operating on byte stride. UTF-8 well-formedness is a documented invariant the producer MUST uphold — the module stores raw bytes and never validates in-band.

Availability: first shipped with mindc 0.4.0+; as of mindc 0.7.1 the std-surface layer is the shipped default (no opt-in flag).

Layout

  • Struct: three i64 fields — data_addr, len, cap.
  • Stride: 1 byte per slot (byte loads through __mind_load_i64 + mask).
  • Initial capacity: 16 bytes.
  • UTF-8: a documented invariant, not enforced by the module.

Public API

  • string_new() -> String
  • string_push_byte(s: String, b: i64) -> String
  • string_push_str(s: String, t: String) -> String
  • string_get(s: String, i: i64) -> i64
  • string_set(s: String, i: i64, b: i64) -> String
  • string_len(s: String) -> i64
  • string_capacity(s: String) -> i64
  • string_free(s: String) -> i64

Example

use std.string;

fn main() -> i64 {
    let s = string_new();
    let s = string_push_byte(s, 0x48); // 'H'
    let s = string_push_byte(s, 0x69); // 'i'

    let n = string_len(s); // 2
    string_free(s);
    return n;
}

For real-world I/O, pair std.string with std.io.print_bytes on stdout/stderr.

Forking for stricter invariants (Phase D)

The bundled std.stringdocuments UTF-8 well-formedness as a producer invariant but doesn’t validate inline — a regulated deployment that wants in-band validation can ship its own string.mind and point MIND_STDLIB_PATH=path at it. The project loader swaps the bundled blob at parse time without recompiling mindc. Shipped in v0.4.3 (RFC 0005 Phase D₁); see std.vecfor the full override contract.