Is there a macro that converts an error into a panic, like a macro try? Do I need to define my own?
For example, I would like to panic if the unit test cannot open the file. My current workaround is this:
macro_rules! tryfail {
($expr:expr) => (match $expr {
result::Result::Ok(val) => val,
result::Result::Err(_) => panic!(stringify!($expr))
})
}
fn foo() {
let c = tryfail!(File::open(...));
}
source
share