www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Result and Option types

reply powerboat9 <powerboat9.gamer gmail.com> writes:
Does dlang have an analog to Result or Option types from rust?
Jul 25 2020
next sibling parent FreeSlave <freeslave93 gmail.com> writes:
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.
Jul 25 2020
prev sibling parent Paul Backus <snarwin gmail.com> writes:
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
Jul 25 2020