Structs
The following code shows basic use of a struct.
Point: struct {
x: float
y: float
}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 xWe can also implement methods on our structs. This will feel very familiar for people with Rust experience.
Last updated