Module 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.

Example

Expect!(int, string) even(int i) @nogc {
    if (i % 2 == 0) {
        return typeof(return).expected(i);
    } else {
        return typeof(return).unexpected("not even");
    }
}

assert(even(1) == unexpected("not even"));
assert(even(2) == 2);

Functions

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

Structs

NameDescription
Expect The expect type can be used to return values and error codes from functions
Unexpected Used in the Expect type to denote an unexpected value

Manifest constants

NameTypeDescription
isExpect Evaluates to true if T is a Expect type

Global variables

NameTypeDescription
anyUnexpected immutable(ddash.utils.expect.AnyUnexpected) Can be used to compare for any unexpected, i.e. Expected<U, V> == anyUnexpected