use native_dialog::{MessageDialog, MessageType};
pub trait DialogExpect<T> {
fn dialog_expect(self, title: &str, msg: &str) -> T;
}
impl<T> DialogExpect<T> for std::option::Option<T> {
fn dialog_expect(self, title: &str, msg: &str) -> T {
match self {
Some(v) => v,
None => {
dialog_panic_internal(title, msg);
}
}
}
}
impl<T, E> DialogExpect<T> for std::result::Result<T, E> {
fn dialog_expect(self, title: &str, msg: &str) -> T {
match self {
Ok(v) => v,
Err(_) => {
dialog_panic_internal(title, msg);
}
}
}
}
#[allow(unused_must_use)]
#[allow(dead_code)]
pub(crate) fn dialog_panic_internal(title: &str, msg: &str) -> ! {
MessageDialog::new()
.set_title(title)
.set_text(msg)
.set_type(MessageType::Error)
.show_alert();
panic!("{msg}");
}
pub fn dialog_panic(title: &str, msg: &str) -> ! {
dialog_panic_internal(title, msg);
}