Expected

Expected!(T, E) is a type that represents either success or failure.

Type T is used for success value. If T is void, then Expected can only hold error value and is considered a success when there is no error value.

Type E is used for error value. The default type for the error value is string.

Default behavior of Expected can be modified by the Hook template parameter.

Constructors

this
this(auto ref CT val)

Constructs an Expected with value or error based on the tye of the provided.

this
this(auto ref E val, bool success)

Constructs an Expected with value or error based on the provided flag. This constructor is available only for cases when value and error has the same type, so we can still construct Expected with value or error.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Postblit

A postblit is present on this object, but not explicitly documented in the source.

Members

Functions

empty
bool empty()

Range interface defined by empty, front, popFront. Yields one value if Expected has value.

error
inout(E) error()

Returns the error value. May only be called when hasValue returns false.

front
inout(T) front()
T front()

Range interface defined by empty, front, popFront. Yields one value if Expected has value.

hasError
bool hasError()
bool hasError()

Checks if Expected has error

hasValue
bool hasValue()
bool hasValue()

Checks if Expected has value

opAssign
void opAssign(auto ref CT rhs)

Assigns a value or error to an Expected.

opCast
bool opCast()
bool opCast()

Implicit conversion to bool.

opEquals
bool opEquals(const auto ref T rhs)
bool opEquals(auto ref T rhs)

Checks whether this Expected object contains a specific expected value.

opEquals
bool opEquals(const auto ref Expected!(T, E, Hook) rhs)
bool opEquals(auto ref Expected!(T, E, Hook) rhs)

Checks whether this Expected object and rhs contain the same expected value or error value.

popFront
void popFront()

Range interface defined by empty, front, popFront. Yields one value if Expected has value.

toHash
size_t toHash()
size_t toHash()

Calculates the hash value of the Expected in a way that iff it has a value, it returns hash of the value. Hash is computed using internal state and storage of the Expected otherwise.

value
inout(T) value()

Returns the expected value if there is one.

Meta