function
ok
ok(v) -> result
Wraps a success value in a result — the value type a fallible function returns. A result carries either a success payload (this) or a failure message (from err), and a caller recovers it with try/else or classifies it with is_ok / is_err. A function that can fail declares -> result and returns ok(value) on the happy path.
The payload is any i32-width scalar — int, fixed, bool, or entity.
Parameters
vthe success payloadExample
program Parse {
function to_digit(c: int) -> result {
if c >= 48 and c <= 57 { return ok(c - 48) } # '0'..'9'
return err("not a digit")
}
test "ok carries the parsed value" {
let d = try to_digit(55) else { 0 } # '7' -> 7
expect_eq(d, 7)
}
}