Rux Language Reference

This reference describes the Rux language exactly as rux 0.4.0 implements it: every type, expression, statement and declaration, the rules the compiler enforces and the messages it prints when a rule is broken. Every example on these pages compiles with rux 0.4.0.

It is written for looking things up. To learn the language from the beginning, follow Learn Rux — a course of short, runnable lessons — and come back here for the full rules. The Introduction explains how the chapters are organised and the grammar notation they use.

The basics

Introduction
Design goals, a first program, and how to read this reference.
Lexical structure
Source files, comments, identifiers, keywords, literals and operator tokens.
Types
Integers, floating point, booleans, characters, text and type aliases.
Bindings
let, var and const, initialisation and destructuring.
Expressions
Every operator, its precedence, and casts with as.
Statements
if, the four loops, labelled break and continue, and return.
Patterns
match, exhaustiveness, and every pattern form.

Functions and data

Functions
Declarations, parameters, overloading, function types and Main.
Structures
Structs, methods with typed receivers, constructors and extensions.
Enumerations
Scalar enums with a backing type and explicit values.
Variants
Tagged unions whose cases carry their own data.
Unions
Untagged overlays of several types in one place.
Tuples
Anonymous products, the unit type and structural equality.
Arrays
Fixed-length T[N], repeat literals and bounds checks.
Slices
Read-only T[..] and writable var T[..] views.
Ranges
The six range forms and where they are used.

Absence and failure

Optionals
T? and none, ?? fallbacks and ? propagation.
Errors
Fallibles T ! E, fail, catch, propagation and panics.
Sum types
A | B values, typed patterns and the is test.

Memory and ownership

References
Borrowing with &T and &var T, and the exclusivity rule.
Pointers
*T and *var T, @ and *, null, arithmetic and slicing.
Ownership
Copies and moves, destructors and defer.
Memory layout
sizeof, alignof, padding and the layout of native forms.

Abstraction

Interfaces
Declarations, interface values, core interfaces, operators, indexers and iteration.
Generics
Generic functions, types and methods, and bounds.
Modules
Packages and modules, imports and pub visibility.

Compile time and platform

Compile time
when, the #target, #build, #compiler, #source and #config context, intrinsics and diagnostics.
Attributes
#Link, #Abi, #NoReturn, #Warn, #Error, #Allow and #Format.
Foreign Function Interface
extern declarations, linking libraries and inline assembly.

Appendix

Package manifests, dependencies and publishing are covered in Packaging, and the standard packages in the API Reference.