Structs and impl

Structs are named product types. Methods go in an impl block. Operators, spread syntax, and destructuring apply to any struct without extra opt-in.

Declaration

scratch.xs

Fields can have type annotations and defaults:

scratch.xs

Impl blocks

Methods take self explicitly. Static methods (no self) use the static keyword.

scratch.xs

Operator overloading

Define operators as method names in an impl block. Overloadable:+, -, *, /, %, ==, !=, <, >, <=, >=, ++, &&, ||.

scratch.xs

Spread / update syntax

Create a new struct based on an existing one, overriding specific fields. The original is not modified.

scratch.xs

Destructuring

scratch.xs

Derives

Auto-implement common traits with derives or the #[derive(...)] attribute syntax:

scratch.xs