You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
neovide/src/error_handling.rs

19 lines
629 B
Rust

use msgbox::IconType;
pub trait ResultPanicExplanation<T, E: ToString> {
fn unwrap_or_explained_panic(self, title: &str, explanation: &str) -> T;
}
impl<T, E: ToString> ResultPanicExplanation<T, E> for Result<T, E> {
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
}
}
}