Crate expect_macro [] [src]

The expect! macro

This crate adds the expect! macro, which is basically just calling .expect on your type but also:

  • Includes the exact line number of the error
  • Allows you to specify a custom error message with formatting.
  • Lazy evaluates error conditions (unlike result.expect(&format!(...)))

This gives you panic messages like this:

thread 'example' panicked at '"expect error"', src/

As opposed to:

thread 'example' panicked at 'called `Result::unwrap()` on an `Err` value: "expect error"', libcore/


If you need to include the Err in a custom error message then do this instead:

let result = Err("expect error");
result.unwrap_or_else(|err| panic!("Got {} but expected 42", err));



Unwrap a result or panic! with a message.



Used to ensure either Option or Result are the Result type.