Arrays & Slices
Array length is part of the type and must be known at compile time.
Arrays
Section titled “Arrays”Heap arrays use an owning pointer:
Length Inference
Section titled “Length Inference”Use _ in the array length or infer the whole type:
Mutability
Section titled “Mutability”Array types do not encode binding mutability. Put ! after the binding name to allow element writes
and replacement of the complete array:
Nested Arrays
Section titled “Nested Arrays”Jiang does not need a separate multidimensional array form. Repeated array suffixes build nested arrays:
Read Int[2][3] as Int -> Int[2] -> Int[2][3].
Slices
Section titled “Slices”T[] is an unsized array type whose length is known at runtime. Bare T[] is not a normal by-value
type. Use T[]& for a borrowed runtime-length view over
contiguous storage. The borrowed slice does not own the storage.
Sentinel slices use T[:S]&. A string literal naturally has type UInt8[:0]&; use text.slice()
or text$.as(UInt8[]&) when a non-literal sentinel slice must be viewed as a plain UInt8[]&:
Indexing a slice can produce an element reference:
T[]& is a borrowed view and does not own the underlying storage. Vector<T>.slice() returns such a
borrowed view. T[]^ is the owned unsized array handle. Use
Vector<T>.into_slice() when the vector should be consumed and its initialized items should become
an owned T[]^; the original vector is moved and cannot be used afterward.
Raw Pointer Views
Section titled “Raw Pointer Views”T* is the raw pointer form for contiguous elements without a length:
Raw-pointer indexing is unsafe because the pointer carries no length. T* supports reads and T*!
supports reads and writes. Use T[]& when Jiang code needs a borrowed length-bearing view; the old
T[*] and T[*:S] types have been removed.