Skip to main content

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) -> IntNumber of characters in a string
string_concat(a: String, b: String) -> StringConcatenate two strings
array_push(arr: T[], value: T)Append a value (mutates the array)
array_len(arr: T[]) -> IntNumber of elements in an array
clock() -> IntUnix timestamp in milliseconds
assert(cond: Bool)Panic with "assertion failed" if cond is false
assert_msg(cond: Bool, 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;
}

Int, Float, Bool, and String 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;
}

Int implements From<Float> (truncating cast) and Float implements From<Int>. 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()() -> IntNumber of characters in the string
.to_string()() -> StringReturns the string itself