Skip to content

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

@bvssvni

Description

@bvssvni

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions