Thread overview
Result and Option types
Jul 25, 2020
powerboat9
Jul 25, 2020
FreeSlave
Jul 25, 2020
Paul Backus
July 25, 2020
Does dlang have an analog to Result or Option types from rust?
July 25, 2020
On Saturday, 25 July 2020 at 18:06:51 UTC, powerboat9 wrote:
> Does dlang have an analog to Result or Option types from rust?

Standard library has std.typecons.Nullable https://dlang.org/phobos/std_typecons.html#Nullable

Note that objects are nullable by themselves as classes are reference types.

As for Result it's easy to implement using Tuple and writing some additional functions.
July 25, 2020
On Saturday, 25 July 2020 at 18:06:51 UTC, powerboat9 wrote:
> Does dlang have an analog to Result or Option types from rust?

In addition to Nullable in the standard library, there are some packages on dub you might find useful:

* optional: an option type that can also function as a range, for compatibility with std.algorithm.
  Link: https://code.dlang.org/packages/optional

* expected: a result type with customizable error behavior (can panic or throw on failed unwrap) and utility functions for monadic error handling (map, andThen, orElse).
  Link: https://code.dlang.org/packages/expected