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