Introduction

Rux is a fast, compiled, strongly typed, multi-paradigm programming language. It compiles to native machine code, checks types and ownership at compile time, and keeps the cost of every construct visible in the source. The same language serves command-line tools, libraries and system code.

This reference describes the language as rux 0.4.0 implements it: what each construct means, which forms are accepted, and what the compiler reports when a rule is broken. Rux is developed in the open across the rux-lang repositories and released under the MIT license.

Design goals

GoalWhat it means in practice
PerformanceNative code, no garbage collector, no hidden allocation. A value's size and layout follow from its type.
SafetyStrong static types, explicit conversions, explicit moves, and borrows the compiler checks.
ClarityRegular syntax and few implicit rules: a cast is written as, a move is written <-, a failure is written fail.
Multi-paradigmProcedural code, methods and interfaces, generics, and pattern matching over sums, optionals and fallibles.
ToolingOne rux binary builds, runs, tests, formats, documents and publishes packages.

Hello, World

import Io::PrintLine;

func Main() -> int {
    PrintLine("Hello, World!");
    return 0;
}

import brings PrintLine from the Io package into scope; the package is listed under [Dependencies] in the project's Rux.toml. Main is the entry point of an executable, and the int it returns is the process exit status. rux run builds and runs the program.

How this reference is organised

The chapters build from the bottom up:

Notation

Rux code blocks hold complete Rux, or a fragment of a function body that compiles once placed in one. Comments such as // 255 show the value an expression produces.

Grammar is given in plain-text blocks with this notation:

NotationMeaning
Rule ::= …Defines the rule Rule
'func'The exact token, written as it appears in source
'a'…'z'Any one character in the range
NameAnother rule, written in PascalCase
A BA followed by B
A | BEither A or B
A?A, optionally
A*Zero or more A
A+One or more A
( … )Grouping
…A part described in the prose rather than spelled out

For example, a type alias is:

TypeAlias ::= 'pub'? 'type' Identifier '=' Type ';'

Error messages are quoted exactly as rux prints them, without the file and position prefix: error: integer literal is out of range for type 'uint8'.

Reference and Learn Rux

The Learn Rux course teaches the language in order, one runnable lesson at a time, and explains why each feature exists. This reference is for looking things up: each page states the complete rule for one construct, lists every form and error, and links to the lesson that teaches it. Read the course to learn Rux; come here to check a detail.

See also