docs / Getting Started / Structs

Structs

Structs are value types with named fields. Construct them using named arguments.

use system.io

struct User
    name String
    age int

fn greet(u User)
    println(f"{u.name} is {u.age} years old")

fn main()
    let u = User(name: "Alice", age: 30)
    greet(u)

Structs can be passed to and returned from functions. Small structs (all primitive fields, <= 128 bytes) are auto-copied on assignment — no reference counting overhead.