"Language Syntax Reference"

Reference: Language Syntax

This page provides the canonical structural layout for Vox v0.3 features. All code samples are grounded in the confirmed examples/golden/ files.

Primitive Types

TypeExampleDescription
str"hello world"Text string (UTF-8)
int42Signed 64-bit integer
float3.1415964-bit floating point number
booltrue, falseBoolean value
Unit()Equivalent to void

Variable assignments are immutable by default in Vox. Prefix with mut for mutability.

fn demo_vars() {
    let x = 10
    let mut y = 20
    y = 30
}

Functions mapping natively to networking, storage, or internal agentic constraints.

fn add(a: int, b: int) -> int {
    return a + b;
}

component Button(label: str) {
    view: <button>{label}</button>
}
@mcp.tool "Calculate the sum of two integers"
fn sum(a: int, b: int) -> int {
    return a + b
}

Lexical constraints and properties can be modeled strictly using Abstract Data Types (ADTs) and Table definitions.

type NetworkState = 
    | Disconnected
    | Connecting
    | Connected(address: str, port: int)
// vox:skip
@table type Task {
    title: str
    done: bool
    owner: str
}

Branching

fn demo_flow(val: int) {
    if val > 10 {
        print("large");
    } else {
        print("small");
    }

    for i in [1, 2, 3] {
        print(i);
    }

    while false {
        break;
    }
}

Pattern Matching (match)

fn handle_state(net_state: NetworkState) {
    match net_state {
        Disconnected -> print("offline")
        Connecting -> print("connecting...")
        Connected(address, port) -> print("connected to " + address)
    }
}

Pipe Operator (|>)

The |> operator passes the expression on the left as the first argument to the function on the right. Works with any function.

// vox:skip
let value = " 123 " |> trim |> parse_int |> double
// Compiles to: double(parse_int(trim(" 123 ")))

Loops

// vox:skip
loop {
    if should_exit() { break }
    continue
}

Comments

Comments use //. Block comments and # comments are not supported.

// vox:skip
// This is a comment
let x = 1

Error Propagation (?)

The ? suffix unpacks an Ok result, returning early if the result is an Error(e).

// vox:skip
fn build_report() -> Result[str] {
    let raw_data = get_data()?
    return Ok("Report { " + raw_data)
}

Actors operate isolated asynchronous loops responding to discrete event handler payloads via on.

actor Counter {
    on increment(current: int) -> int {
        let count = current + 1
        print("Count is " + count)
        ret count
    }
}
fn run() {
    let c = spawn(Counter)
    c.increment(0)
}

Agents

Agents define LLM-backed roles with systematic instructions and toolsets.

agent Assistant {
    version "1.0.0"

    on greet(name: str) -> str {
        return "Hello " + name + ", how can I assist you today?"
    }

    migrate from "0.9.0" {
        print("Migrating data...")
    }
}

Use workflow to group state machine processes that survive process restarts. Use activity to dictate atomic, retry-able execution sequences.

@query fn get_notes() -> List[Note] {
    ret db.Note.all()
}

@mutation fn create_note(title: str, content: str) -> Result[Id[Note]] {
    let id = db.Note.insert({ title: title, content: content })?
    ret Ok(id)
}

workflow order(id: str) -> Result[Unit] {
    let status = check_inventory(id)
    ret Ok(Unit)
}

Island and UI Syntax

The @island directive dictates interactive DOM components.

// vox:skip
@island TaskList { tasks: list[Task] }

// Web Routing Layout Mapping
routes {
    "/"         -> TaskList
    "/about"    -> AboutPage
}

Return Keyword aliasing

ret is a short-form alias for return; both are valid and produce identical behavior. Use ret for one-liners and return for complex logic.

// vox:skip
fn double(x: int) -> int { ret x * 2 }
fn square(x: int) -> int { return x * x }

Vox imports use fully qualified paths. Use import rust:<crate> for native interop.

// vox:skip
import react.use_state
import rust:serde_json as json