Strings

The "hello world" string literal creates a string object.

Ad Astra strings are immutable arrays of unsigned bytes that encode Unicode strings. These values are compatible with Rust's immutable str type.

Since strings are arrays of bytes, script code can concatenate them using the array constructor.

["hello", " ", "world"] == "hello world";

The script engine interprets strings slightly differently than normal byte arrays, considering that these arrays encode text data:

  1. The array constructor attempts to stringify each argument into a string during the argument type casting. This feature is particularly useful for constructing formatted strings.

    let x = 10;
    
    // Prints "The value of x is 10".
    dbg(["The value of x is ", x]);
    
  2. The string index operator indexes by the string's Unicode characters rather than the underlying bytes.

    "hello world"[1] == "e";
    "hello world"[1..7] == "ello w";