assert(err("foo").expectErr("oops") == "foo"); version (D_Exceptions) { () @trusted { assert(collectExceptionMsg!Throwable(Expected!int.init.expectErr("oops")) == "oops: empty"); assert(collectExceptionMsg!Throwable(ok(42).expectErr("oops")) == "oops: 42"); assert(collectExceptionMsg!Throwable(ok().expectErr("oops")) == "oops: empty"); // void value }(); } assert(ok("foo").expect!(a => "bar") == "foo"); assert(err!string("foo").expect!(a => "bar") == "bar"); assert(err!string("foo").expect!((a) {}) is null); assert(ok("foo").expectErr!(a => "bar") == "bar"); assert(err!string("foo").expectErr!(a => "bar") == "foo"); assert(ok!string("foo").expectErr!((a) {}) is null);
Unwraps a result, yielding the content of an error value. If there is none, or success value, it throws assert(0) with the provided message.