-
-
Notifications
You must be signed in to change notification settings - Fork 55
Closed
Labels
Description
Dyon uses a separate dynamic type for result values. The result type has two variants, err
and ok
. It has a lot of common with option value, but there are a few differences.
err(x)
creates an error with messagex
, using deep cloneok(x)
creates a successful result with valuex
, using deep cloneunwrap(x)
unwraps a result type, when error prints error message plus?
trace messagesunwrap_err(x)
unwraps error messageis_err(x)
returnstrue
if result is an error
For both result and option, the ?
operator propagates the error (requires ->
on function):
x?
,x.a?
,x[0]?.b.c?
etc.foo()?
or following after any expression
When a the value is none()
or err(x)
, the ?
operator propagates the error. Returns from the function. A trace message is added to help debugging on unwrap
, describing where the ?
operation happened. some(x)
is converted to ok(x)
.
This is designed for:
- Explicit decide whether to use result
- Check when mutating a variable that it is result
- Convenient for debugging
- Common way of handling errors