Structs

The following code shows basic use of a struct.

Point: struct {
    x: float
    y: float
}
circle-info

Comma separation is optional in struct initialization and definition.

Point is thus defined as a data structure containing two float fields xand y.

You can define instances of Pointlike so:

point0 := new Point {
    x: 100
    y: 200
}

point1: Point = new Point {
    x: 1
    y: 2
}

Struct fields are always mutable. You can access fields of a struct like this:

point := new Point {
    x: 100
    y: 100
}

point x = 20
point y = point x
circle-info

Wu does not use .for field access, because doing so would be gross.

We can also implement methods on our structs. This will feel very familiar for people with Rust experience.

circle-info

Self aliases whatever struct type you're implementing on.

Last updated