Skip to main content
Version: 0.8.0

Runtime

Panics

A panic is a hard, unrecoverable runtime error. It prints a message and exits the process with a non-zero status. Panics cannot be caught.

Panics are triggered by:

  • .yolo() on None or a Result::Err
  • Out-of-bounds array access
  • Integer division by zero
  • assert(false) or assert_msg(false, msg)

Built-in Functions

These are available in every module without any import declaration (provided by std::core auto-import):

NameSignatureDescription
print<T>(v: T)Print to stdout, no newline
println<T>(v: T)Print to stdout with newline
string_len(s: String) -> i64Number of characters in a string
string_concat(a: String, b: String) -> StringConcatenate two strings
clock() -> i64Unix timestamp in milliseconds
assert(cond: boolean)Panic with "assertion failed" if cond is false
assert_msg(cond: boolean, msg: String)Panic with msg if cond is false
dbg<T>(v: T) -> TPrint [dbg] <value> to stderr and return the value unchanged

Built-in Aspects

The following aspects are pre-implemented for built-in types:

Display

aspect Display {
fun to_string(&self) -> String;
}

i64, f64, boolean, String, and Char implement Display. .to_string() returns the canonical string representation. print and println accept any Display type.

Iterable<T>

aspect Iterable<T> {
fun next(&mut self) -> Perhaps<T>;
}

T[] (array) and Range (from .. / ..=) implement Iterable<T>. User-defined types may implement it to be usable in for-in.

From<S>

aspect From<S> {
fun from(value: S) -> Self;
}

i64 implements From<f64> (truncating cast) and f64 implements From<i64>. The as operator desugars to T::from(value). User-defined types may implement From<S> to enable as casts and ? error coercion.

String Methods

MethodSignatureDescription
.len()() -> i64Number of characters in the string
.to_string()() -> StringReturns the string itself

Array Methods

T[] and [T; N] both expose:

MethodSignatureDescription
.len()() -> i64Number of elements

Char Methods

Since v0.8.0.

Method / FunctionSignatureDescription
.to_u32()() -> u32Unicode scalar value as a u32
Char::from_u32(n)(u32) -> Perhaps<Char>Construct from a code point; None if invalid
.to_string()() -> StringSingle-character string