Skip to content

Structs

Structs are the primary way to define custom data types in Run.

package main
use "fmt"
pub type Point struct {
x: f64
y: f64
}
pub fun main() {
p := Point{ x: 3.0, y: 4.0 }
fmt.println(p.x)
fmt.println(p.y)
}

Struct fields are accessed using dot notation.

p := Point{ x: 1.0, y: 2.0 }
p.x = 5.0
fmt.println(p.x) // 5.0

Structs can be made public with pub. Field visibility follows the same rules — fields are private by default within the struct’s package.

pub type Config struct {
pub host: string
pub port: int
secret: string // private to this package
}

Methods are declared separately from structs and are covered in a later chapter.