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
| Goal | What it means in practice |
|---|---|
| Performance | Native code, no garbage collector, no hidden allocation. A value's size and layout follow from its type. |
| Safety | Strong static types, explicit conversions, explicit moves, and borrows the compiler checks. |
| Clarity | Regular syntax and few implicit rules: a cast is written as, a move is written <-, a failure is written fail. |
| Multi-paradigm | Procedural code, methods and interfaces, generics, and pattern matching over sums, optionals and fallibles. |
| Tooling | One 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:
| Part | Chapters |
|---|---|
| Text of a program | Lexical structure |
| Values | Types, bindings, expressions, statements, patterns |
| Declarations | Functions, structs, enums, variants, unions |
| Compound types | Tuples, arrays, slices, ranges, references, pointers |
| Absence and failure | Optionals, errors, sums |
| Abstraction | Ownership, interfaces, generics, modules |
| Compile time and FFI | Compile-time evaluation, attributes, foreign functions, memory layout |
| Appendix | Primitive types, tokens, the RCU object format |
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:
| Notation | Meaning |
|---|---|
Rule ::= … | Defines the rule Rule |
'func' | The exact token, written as it appears in source |
'a'…'z' | Any one character in the range |
Name | Another rule, written in PascalCase |
A B | A followed by B |
A | B | Either 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
- Learn Rux — the course, from installation to complete programs
- Hello — the first lesson, with this program explained line by line
- Playground — run Rux in the browser
- Packaging — manifests, dependencies and publishing
- Command-line interface — every
ruxcommand
Overview
The complete reference for the Rux language as implemented by rux 0.4.0 — lexical structure, types, expressions, functions, data types, optionals, errors, ownership, interfaces, generics, modules, compile-time programming and FFI.
Source Files
How Rux source files are named, encoded and split into tokens: UTF-8 text, whitespace, and the longest-match rule.