Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result value design (err(x)/ok(x)) #82

Closed
bvssvni opened this issue Mar 19, 2016 · 0 comments
Closed

Result value design (err(x)/ok(x)) #82

bvssvni opened this issue Mar 19, 2016 · 0 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented Mar 19, 2016

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 message x, using deep clone
  • ok(x) creates a successful result with value x, using deep clone
  • unwrap(x) unwraps a result type, when error prints error message plus ? trace messages
  • unwrap_err(x) unwraps error message
  • is_err(x) returns true 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant