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
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
}
[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
| Kind | Types | Literals |
|---|---|---|
| Signed integers | int8 … int512, int (pointer-sized) | 42, -7, 5i64 |
| Unsigned integers | uint8 … uint512, uint, byte (= uint8) | 200u8, 0xFF, 0b1010, 1_000_000 |
| Floating point | float32, float64, float (= float64) | 0.75f32, 2.998e8 |
| Boolean | bool | true, false |
| Character | char (= char32), char8, char16 | 'R', '\u{263A}', c8'R' |
| Text | char8[..] — a slice of UTF-8 bytes | "hello" |
| Array, slice | T[N], T[..], var T[..] | [2, 3, 5], [0; 16] |
| Tuple | (A, B) | (3, true) |
| Optional | T? | none |
| Fallible | T ! E, ! E | — |
| Sum | A | B | — |
| Reference, pointer | &T, &var T, *T, *var T | @x, null |
| Function | func(int32) -> int32 | a 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
| Placeholder | Result |
|---|---|
{} | 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
| Command | What it does |
|---|---|
rux new Name | Create a package |
rux check | Compile without building — the fastest error check |
rux build | Build into Bin/Debug/<OS>/<Arch>/ |
rux run | Build and run; --release for an optimised build |
rux fmt | Format the sources |
rux lint | Report style problems |
rux test | Build and run the packages under Tests/ |
rux doc | Generate documentation from /// comments |
Lessons: Your first project, Tooling · Reference: CLI
Learn with AI
Use Claude Code, Codex or a chat assistant as a study partner for the Rux course — set them up with the right context, use ready-made prompts, and let the compiler check every answer.
Overview
First programs: printing, values and their types. Twelve short lessons that take you from Hello, World to every primitive type and how to convert between them.