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.

struct Expected (
T
E = string
Hook = Abort
) if (
!is(E == void) &&
(
isVoidValueEnabled!Hook ||
!is(T == void)
)
) {}

Constructors

this
this(CT val)

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

this
this(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.

this
this()
Undocumented in source.

Destructor

~this
~this()
Undocumented in source.

Postblit

this(this)
this(this)
Undocumented in source.

Members

Functions

opAssign
void opAssign(CT rhs)

Assigns a value or error to an Expected.

opCast
bool opCast()

Implicit conversion to bool.

opEquals
bool opEquals(T rhs)

Checks whether this Expected object contains a specific expected value.

opEquals
bool opEquals(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()

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.

Properties

empty
bool empty [@property getter]

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

empty
bool empty [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
error
inout(E) error [@property getter]

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

error
E error [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
front
inout(T) front [@property getter]
T front [@property getter]

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

hasError
bool hasError [@property getter]

Checks if Expected has error

hasValue
bool hasValue [@property getter]

Checks if Expected has value

value
inout(T) value [@property getter]

Returns the expected value if there is one.

value
T value [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Parameters

T

represents type of the expected value

E

represents type of the error value.

Hook

defines the Expected type behavior

Meta