expect

Unwraps a result, yielding the content of expected value. If there is none, or error value, it throws assert(0) with the provided message.

  1. T expect(auto ref EX res, lazy string msg)
    @safe
    T
    expect
    (
    EX : Expected!(T, E, H)
    T
    E
    H
    )
    (
    auto ref EX res
    ,
    lazy string msg
    )
  2. T expect(auto ref EX res)

Parameters

res
Type: EX

Expected to check the result of

msg
Type: string

message to use with assert

Examples

assert(ok(42).expect("oops") == 42);
ok().expect("oops"); // void value
assert(collectExceptionMsg!Throwable(Expected!int.init.expect("oops")) == "oops: empty");
assert(collectExceptionMsg!Throwable(err!int("foo").expect("oops")) == "oops: foo");

Meta