Interfaces
Structured values with typed fields and methods, constructors, generics, and the native struct ABI.
An interface declares a structured type: a set of typed fields plus methods that close over them. The interface name is also the constructor.
Fields are written in declaration order. The constructor takes one argument per field, in that order. Semicolons and commas both separate fields; the manuals use both styles.
Methods and self
Methods are declared inside the interface body without a fn keyword. self refers to the receiver.
Methods may call free functions, group functions, and external libraries. They may return a new instance of the same interface.
Field access and assignment
Field assignment is a normal assignment target. When the interface is represented as a native C struct, field writes lower directly to the corresponding C member; otherwise they take the boxed member path.
Constructors
The constructor name may be qualified by a group. External libraries use this heavily: vlin.Types.Matrix(...), vstat.Series(data, n), vchem.Graph(...).
Generic interfaces
Type parameters are monomorphized like generic functions. Nested generic annotations such as Nested<Int64> are accepted.
Native struct ABI
Struct-typed values participate in the native boundary:
- a struct parameter expands into one C argument per field, in declaration order;
- a struct return uses an out-parameter;
- a registered field layout makes field access constant-time (
last_field_idx); - arrays of native structs are supported, with boxed fallbacks where needed.
This is what lets a library pass Matrix { row, col, data } across the native boundary without boxing every field. On AVR it is what keeps a four-field struct on registers instead of forcing an arena round-trip.
An interface is eligible for native C representation when every field has a C-compatible type and the layout is registered. Libraries that need a native surface keep their hot types in this shape (vlin.Types.Matrix, vfft.Plan, vml.Types.Dense).
Arrays of structs
For performance-sensitive arrays, @layout<soa> lowers struct scratch to one packed array per field. See Memory & Regions.
Lifetimes
A struct allocated inside a region is invalid after the rewind unless it was committed or moved. Region escape analysis catches direct assignments, but a pointer stored inside a struct field can still outlive its region. Do not rely on the checker to see through every field.