Result

Undocumented in source.

Alias This

st

Members

Aliases

Err
alias Err = .Err!E
Undocumented in source.
Ok
alias Ok = .Ok!T
Undocumented in source.
back
alias back = front
Undocumented in source.
empty
alias empty = isErr
Undocumented in source.
length
alias length = isOk
Undocumented in source.
opDollar
alias opDollar(size_t dim : 0) = length
Undocumented in source.
popBack
alias popBack = popFront
Undocumented in source.

Functions

front
inout(T) front()
Undocumented in source. Be warned that the author may not have intended to support it.
isErr
bool isErr()
Undocumented in source. Be warned that the author may not have intended to support it.
isOk
bool isOk()
Undocumented in source. Be warned that the author may not have intended to support it.
opAssign
auto ref opAssign(U rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opAssign
auto ref opAssign(U rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(Result rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(U rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
ref opIndex()
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
inout(T) opIndex(size_t index)
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
ref opIndex(size_t[2] dim)
Undocumented in source. Be warned that the author may not have intended to support it.
opSlice
size_t[2] opSlice(size_t start, size_t end)
Undocumented in source. Be warned that the author may not have intended to support it.
popFront
void popFront()
Undocumented in source. Be warned that the author may not have intended to support it.
save
inout(Result) save()
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

err
err(U err)
Undocumented in source. Be warned that the author may not have intended to support it.
ok
ok(U ok)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

st
SumType!(Ok, Err) st;
Undocumented in source.

Examples

alias R = Result!int;

assert(R.ok(3) == Ok!int(3));
assert(R.err("failure") == Err!string("failure"));

assert(R.ok(3).match!(
	(Err!string) => false, // use Ok/Err to match
	(int) => true,         // or use the underlying type to match
));

assert(R.init == R.init);
assert(R.ok(0) != R.err(""));


static assert(!__traits(compiles, R.init = Ok!(Ok!int).init));
static assert(!__traits(compiles, R.init = Ok!short.init)); // TODO: should this be allowed?

() @trusted
{
	assert((R.ok(3) = 10.ok) == 10.ok);
	assert((R.ok(3) = "failure".err) == "failure".err);
}
();

Meta