use msgbox::IconType; pub trait ResultPanicExplanation { fn unwrap_or_explained_panic(self, title: &str, explanation: &str) -> T; } impl ResultPanicExplanation for Result { fn unwrap_or_explained_panic(self, title: &str, explanation: &str) -> T { match self { Err(error) => { let explanation = format!("{}: {}", explanation, error.to_string()); msgbox::create(title, &explanation, IconType::Error); panic!(explanation); }, Ok(content) => content } } } pub trait OptionPanicExplanation { fn unwrap_or_explained_panic(self, title: &str, explanation: &str) -> T; } impl OptionPanicExplanation for Option { fn unwrap_or_explained_panic(self, title: &str, explanation: &str) -> T { match self { None => { msgbox::create(title, &explanation, IconType::Error); panic!(explanation.to_string()); }, Some(content) => content } } }