Module assert
assert
Runtime assertion and panic functions.
Both panic and assert accept any type that implements the ToString
trait — its .to_string().to_c_str() result is forwarded to the built-in
__yo_panic. The to_c_str() allocates a C string on the heap; the caller
(process termination via abort) does not need to free it.
Usage: assert(x > i32(0), "x must be positive"); assert(opt.is_some(), "Expected Some"); panic("unexpected condition");
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
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Parameters
| Name | Type | Notes |
|---|---|---|
msg | T |
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
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Parameters
| Name | Type | Notes |
|---|---|---|
flag | bool | |
msg | T | default: "Assertion failed." |
Returns: unit