ddash.utils.expect

An expected result type

Useful for functions that are expected to return something but could result in an error. The expected type is parameterized over two types - the expected one and the Unexpected. When you want to assign an unexpected type you must use the provided type constructor to make an unexpected assignment.

An Expect!(T, U) type also has a static expected and unexpected methods to create the given Expect!(U, V) with the desired state.

Members

Functions

unexpected
auto unexpected(E value)

Type constructor for an Unexpected value. This must be used when assigning or passing an unexpected type to an Expect!(T, U)

Structs

Expect
struct Expect(T, E = Variant)

The expect type can be used to return values and error codes from functions

Variables

anyUnexpected
auto anyUnexpected;

Can be used to compare for any unexpected, i.e. Expected<U, V> == anyUnexpected

Examples

1 Expect!(int, string) even(int i) @nogc {
2     if (i % 2 == 0) {
3         return typeof(return).expected(i);
4     } else {
5         return typeof(return).unexpected("not even");
6     }
7 }
8 
9 assert(even(1) == unexpected("not even"));
10 assert(even(2) == 2);

Meta