Skip to content

Instantly share code, notes, and snippets.



Created Sep 7, 2019
What would you like to do?
Central Error Handler
pub fn helper<T, V>(res: Result<T, V>) -> T
V: std::fmt::Debug,
match res {
Ok(val) => val,
Err(err) => {
// This is where errors will be handled.
// Change this accordingly.
log::error!("{:?}", err);
panic!("{:?}", err);
mod tests {
use super::*;
fn shouldnt_panic() {
let ok: Result<&str, &str> = Ok("okay");
let rhs = helper(ok);
assert_eq!("okay", rhs);
fn should_panic() {
let err: Result<&str, &str> = Err("oops");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.