Thread overview | |||||
---|---|---|---|---|---|
|
July 25, 2020 Result and Option types | ||||
---|---|---|---|---|
| ||||
Does dlang have an analog to Result or Option types from rust? |
July 25, 2020 Re: Result and Option types | ||||
---|---|---|---|---|
| ||||
Posted in reply to powerboat9 | 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 Re: Result and Option types | ||||
---|---|---|---|---|
| ||||
Posted in reply to powerboat9 | 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 |
Copyright © 1999-2021 by the D Language Foundation