Result

Result of T. Designed for error handling where an operation can either succeed or fail. - TODO: Add member toRange alias with opSlice - TODO: Add member visit()

Constructors

this
this(T value)
Undocumented in source.

Members

Aliases

hasValue
alias hasValue = isValid
Undocumented in source.

Functions

opAssign
typeof(this) opAssign(T value)
Undocumented in source. Be warned that the author may not have intended to support it.

Properties

invalid
typeof(this) invalid [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
isValid
bool isValid [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
opUnary
inout(T) opUnary [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
value
inout(T) value [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

_isValid
bool _isValid;
Undocumented in source.

Examples

to string conversion

alias R = Result!int;
const R r1;
assert(r1.toString == "invalid");
const R r2 = 42;
assert(r2.toString == "42");

result of uncopyable type

alias T = Uncopyable;
alias R = Result!T;
R r1;
assert(!r1);
assert(r1 == R.invalid);
assert(r1 != R(T.init));
assert(!r1.isValid);
T t = T(42);
r1 = move(t);
assert(r1 != R(T.init));
assert(*r1 == T(42));
R r2 = T(43);
assert(*r2 == T(43));
assert(r2.value == T(43));

Meta