Rux Cheat Sheet

The syntax from the whole course on one page. The snippets are cut from programs that compile with the current rux — … marks a body left out — and each section links to the lessons that explain it. For the complete rules, see the Rux Reference.

A program

Src/Main.rux
import Io::{ Print, PrintLine };   // bring names from a package into scope

func Main() -> int {               // the entry point
    PrintLine("Hello, {}!", "World");
    return 0;                      // the exit status: 0 means success
}
Rux.toml
[Dependencies]
Io = { Namespace = "Rux", Version = "*" }   # every package you import from

Lessons: Hello, World, Console, Comment

Bindings and constants

let year = 2026;                 // immutable, type inferred (int)
var score = 10;                  // mutable
score += 5;
let small: int8 = 100;           // explicit type
const Limit = 100;               // folded in at compile time
const Pi: float32 = 3.1415927f32;

Lessons: Variable, Mutable, Const

Types

KindTypesLiterals
Signed integersint8 … int512, int (pointer-sized)42, -7, 5i64
Unsigned integersuint8 … uint512, uint, byte (= uint8)200u8, 0xFF, 0b1010, 1_000_000
Floating pointfloat32, float64, float (= float64)0.75f32, 2.998e8
Booleanbooltrue, false
Characterchar (= char32), char8, char16'R', '\u{263A}', c8'R'
Textchar8[..] — a slice of UTF-8 bytes"hello"
Array, sliceT[N], T[..], var T[..][2, 3, 5], [0; 16]
Tuple(A, B)(3, true)
OptionalT?none
FallibleT ! E, ! E—
SumA | B—
Reference, pointer&T, &var T, *T, *var T@x, null
Functionfunc(int32) -> int32a function's name
let big = small as int32;        // convert with `as`

Lessons: Integer, Float, Character, Literal, Convert

Control flow

if score > 10 {                  // braces always, parentheses optional
    PrintLine("big");
} else if score > 5 {
    PrintLine("medium");
} else {
    PrintLine("small");
}

let label = n % 2 == 0 ? "even" : "odd";

while n > 0 { n -= 1; }
do { n += 1; } while n < 3;      // runs at least once — note the `;`
loop { break; }                  // until a `break`

for i in 0..3 { }                // 0, 1, 2
for i in 1..=3 { }               // 1, 2, 3

outer: for a in 1..10 {          // a labelled loop
    for b in a..10 {
        if a * b == 12 { break outer; }
    }
}

Lessons: If, Ternary, While, Do-while, Loop, For, Label

match

let kind = match score {
    0 => "none",
    1..=9 => "few",              // a range pattern
    n if n > 1000 => "huge",     // a guard
    else => "many"               // the default arm is `else`, never `_`
};

Lessons: Match, Match expression, Guard, Range pattern, Exhaustive

Functions

func Add(left: int, right: int) -> int {
    return left + right;
}

func Clamp(value: int, low: int = 0, high: int = 100) -> int { … }   // default arguments
func Sum(args: int32...) -> int32 { … }                              // variadic
func Divide(a: int32, b: int32) -> (int32, int32) {                  // several results
    return (a / b, a % b);
}
let (q, r) = Divide(17, 5);                                          // destructure

func Larger<T>(a: T, b: T) -> T {                                    // generic
    return a > b ? a : b;
}

Lessons: Function, Default argument, Variadic, Tuple, Destructure, Generic

Arrays and slices

let primes: int32[4] = [2, 3, 5, 7];
let zeros: int32[8] = [0; 8];    // repeat a value
let part = primes[1..3];         // a slice: a view of elements 1 and 2
PrintLine("{}", primes.length);
for p in primes { }

Lessons: Array, Array repeat, Slice, Writable slice

Structs and methods

struct Point {
    x: int;
    y: int;
}

extend Point {
    func Point(x: int, y: int) -> Point {        // a constructor: named after the type
        return Point { x: x, y: y };
    }

    func Length2(self: &Point) -> int {          // reads its receiver
        return self.x * self.x + self.y * self.y;
    }

    func Move(self: &var Point, dx: int) {       // changes its receiver
        self.x += dx;
    }
}

var p = Point(3, 4);
p.Move(1);

Lessons: Struct, Method, Mutating method, Constructor, Reference

Enums and variants

enum Direction { North, East, South, West }
enum Status: uint16 { Ok = 200, NotFound = 404 }

variant Shape {
    Circle(float64),
    Rectangle { width: float64; height: float64; },
    Empty
}

func Area(shape: Shape) -> float64 {
    return match shape {
        .Circle(r) => 3.14 * r * r,
        .Rectangle { width, height } => width * height,
        .Empty => 0.0
    };
}

Lessons: Enum, Enum value, Variant, Variant match, Struct pattern

Optionals

func FirstEven(values: int[..]) -> int? {
    for v in values {
        if v % 2 == 0 { return v; }
    }
    return none;
}

let found = FirstEven(numbers) ?? -1;            // a fallback
match FirstEven(numbers) {
    value? => PrintLine("{}", value),
    none => PrintLine("none")
}

Lessons: Optional, Presence, Coalesce, Coalesce exit, Optional propagate

Errors

variant ParseError { Empty, Bad(int) }

func Half(n: int) -> int ! ParseError {          // a value, or an error
    if n == 0 { fail ParseError::Empty; }
    if n % 2 != 0 { fail ParseError::Bad(n); }
    return n / 2;
}

func Quarter(n: int) -> int ! ParseError {
    let half = Half(n)?;                         // pass a failure to the caller
    return Half(half)?;
}

match Quarter(8) {
    .Success(v) => PrintLine("{}", v),
    .Failure(e) => PrintLine("failed")
}
let safe = Half(3) catch { else => 0 };          // a default on failure

Lessons: Fallible, Fail, Propagate, Catch, Catch fallback

Sum types

type Setting = int32 | bool;

func Describe(s: Setting) -> char8[..] {
    return match s {
        n: int32 => "number",
        flag: bool => "flag"
    };
}

if limit is bool { }

Lessons: Sum type, Typed pattern, The is operator

Interfaces

interface Named {
    func Name() -> char8[..];
}

extend Point : Named {
    func Name(self: &Point) -> char8[..] {
        return "point";
    }
}

Lessons: Interface, Interface value, Generic bound

Ownership

let b <- a;                      // move: `a` can no longer be used
Take(<-b);                       // move into a call

extend Token {
    func ~Token(self: &var Token) { … }   // a destructor, run when the value goes away
}

defer PrintLine("done");         // runs when the scope ends

Lessons: Copy, Move, Destructor, Defer

Pointers

var score = 10;
let reader: *int = @score;       // `@` takes an address
let writer: *var int = @score;
*writer = 25;                    // `*` reads or writes through it

Lessons: Pointer, Out parameter, Optional pointer

Formatting

PlaceholderResult
{}the value
{{}}a literal {}
{:>6}, {:<6}, {:^6}, {:*^8}right, left, centre aligned; with a fill character
{:.2}two decimals
{:x}, {:X}, {:o}, {:b}, {:#x}hexadecimal, octal, binary; with a prefix
{:08}, {:+}, {:e}zero padded, with a sign, in scientific notation

Lessons: Console, Format, Format number

The rux tool

CommandWhat it does
rux new NameCreate a package
rux checkCompile without building — the fastest error check
rux buildBuild into Bin/Debug/<OS>/<Arch>/
rux runBuild and run; --release for an optimised build
rux fmtFormat the sources
rux lintReport style problems
rux testBuild and run the packages under Tests/
rux docGenerate documentation from /// comments

Lessons: Your first project, Tooling · Reference: CLI