Result

Result of T with optional error E. 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.
this
this(E error)
Undocumented in source.

Destructor

~this
~this()
Undocumented in source.

Members

Functions

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

Properties

error
inout(E) error [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
invalid
typeof(this) invalid [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
isError
bool isError [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
isValue
bool isValue [@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.
opEquals
T opEquals [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
T opEquals [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
typeof(this) opEquals [@property setter]
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.

Examples

to string conversion

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

result of uncopyable type

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

result of pointer and error enum

alias V = ulong;
alias T = V*;
enum E { first, second }
alias R = Result!(T, E);
R r1;
assert(!r1);
assert(r1 == R.invalid);
assert(r1 != R(T.init));
assert(!r1.isValue);
assert(r1.isError);
assert(r1.error == E.init);
assert(r1.error == E.first);
T v = new V(42);
r1 = move(v);
assert(r1 != R(T.init));
assert(**r1 == V(42));

result of pointer and error enum toString

alias V = ulong;
alias T = V*;
enum E { first, second }
alias R = Result!(T, E);
R r1;
assert(r1.toString == "first");
r1 = T.init;
assert(r1.toString == "null");

result of pointer and error enum

alias V = ulong;
alias T = V*;
enum E { first, second }
alias R = Result!(T, E);
R r2 = new V(43);
assert(**r2 == V(43));
assert(*r2.value == V(43));

result of pointer and error enum

alias V = ulong;
alias T = V*;
enum E { first, second }
alias R = Result!(T, E);
R r2 = E.first;
assert(r2.error == E.first);
r2 = E.second;
assert(r2.error == E.second);

Meta