function
is_err
is_err(r: result) -> bool
Tests a result's tag: true when it was built with err, false when it was built with ok. Use it to detect the failure case explicitly — for example to count or log failures — while try/else handles recovering a value. It is the exact negation of is_ok.
Parameters
rthe result to testExample
program Retry {
function step(n: int) -> result {
if n < 3 { return err("not ready") }
return ok(n)
}
test "is_err detects the failure case" {
expect(is_err(step(1)))
expect(not is_err(step(5)))
}
}