Module assert

assert
Stability: **stable in shape, with one caveat worth stating before the freeze.** `panic`, `assert`, `assert_eq`, `assert_ne` and `assert_approx` have the names and the meanings Rust gives them, they accept any `ToString`, and no additions are planned. The caveat is that these are RUNTIME assertions only: there is no `debug_assert` that compiles out, so every `assert` in a release build pays for its condition and its message. Adding one later is additive; changing these five is not expected. Do not reach for `comptime_assert` as the compile-time counterpart without reading its own note — it fires only where the condition folds to a concrete `false`. — stable modules only change additively; this one may still change.

Runtime assertion and panic functions.

Both panic and assert accept any type that implements the ToString trait — its .to_string().to_cstr() result (a NUL-terminated ArrayList(u8)) is handed to the built-in __yo_panic through its data pointer. The process is terminating via abort; the buffer need not be freed.

Usage: assert(x > i32(0), "x must be positive"); assert(opt.is_some(), "Expected Some"); panic("unexpected condition");

Stability

stable in shape, with one caveat worth stating before the freeze. panic, assert, assert_eq, assert_ne and assert_approx have the names and the meanings Rust gives them, they accept any ToString, and no additions are planned. The caveat is that these are RUNTIME assertions only: there is no debug_assert that compiles out, so every assert in a release build pays for its condition and its message. Adding one later is additive; changing these five is not expected.

Do not reach for comptime_assert as the compile-time counterpart without reading its own note — it fires only where the condition folds to a concrete false.

Functions

panic function
fn(generic(T : Type), msg : T, where(T <: ToString)) -> unit

Terminate the program with a message.

msg must implement ToString.

Type Parameters

NameTypeNotes
TTypecomptime

Parameters

NameTypeNotes
msgT

Returns: unit

assert function
fn(generic(T : Type), flag : bool, (msg : T) ?= "Assertion failed.", where(T <: ToString)) -> unit

Runtime assertion. If flag is false, call panic(msg).

msg must implement ToString.

Type Parameters

NameTypeNotes
TTypecomptime

Parameters

NameTypeNotes
flagbool
msgTdefault: "Assertion failed."

Returns: unit

assert_eq function
fn(generic(A : Type), left : A, right : A, (msg : str) ?= "", where(A <: (Eq(A), ToString))) -> unit

Assert two values are equal; on failure the panic PRINTS BOTH SIDES — the diff-printing upgrade over assert(a == b, "..."), whose message can't show what the values actually were.

assert_eq(got, i32(42)); assert_eq(name, yo, "config name round-trip");

Type Parameters

NameTypeNotes
ATypecomptime

Parameters

NameTypeNotes
leftA
rightA
msgstrdefault: ""

Returns: unit

assert_ne function
fn(generic(A : Type), left : A, right : A, (msg : str) ?= "", where(A <: (Eq(A), ToString))) -> unit

Assert two values are NOT equal; prints the (shared) value on failure.

Type Parameters

NameTypeNotes
ATypecomptime

Parameters

NameTypeNotes
leftA
rightA
msgstrdefault: ""

Returns: unit

assert_approx function
fn(left : f64, right : f64, (epsilon : f64) ?= f64(0.000000001), (msg : str) ?= "") -> unit

Assert two floats are within epsilon of each other (absolute difference). The default epsilon (1e-9) suits values near 1.0; pass an explicit epsilon for very large or very small magnitudes.

Parameters

NameTypeNotes
leftf64
rightf64
epsilonf64default: f64(0.000000001)
msgstrdefault: ""

Returns: unit