Skip to content

std/struct

Struct — the interface every struct satisfies, named or anonymous. Its sole function, update, returns a copy of a struct with selected fields replaced, and is reached type-qualified: Struct.update(original, updates).

Import with import std/struct.

Interfaces

interface Struct {
    fn update(original: self, updates: Partial<self>): self
}

The universal struct interface. Every struct value — a named struct type or an anonymous {...} — satisfies Struct, so its functions are callable on any of them; no non-struct type satisfies it. Struct is also usable as a bound (fn f<'T>(x: 'T): 'T where 'T: Struct) and an existential (fn f(s: Struct)).