Use the new GErrorDomain macro

This commit is contained in:
Marc-André Lureau 2021-03-22 17:36:36 +04:00
parent 9580a40c04
commit 33fa975031
2 changed files with 6 additions and 26 deletions

View File

@ -82,7 +82,7 @@ mod imp {
widget.make_current();
if let Err(e) = unsafe { self.realize_gl() } {
let e = glib::Error::new(AppError::GL, &e);
let e = glib::Error::new(QemuGtkError::GL, &e);
widget.set_error(Some(&e));
}
}

View File

@ -1,28 +1,8 @@
use gtk::glib;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AppError {
GL = 1,
Failed = 2,
}
impl glib::error::ErrorDomain for AppError {
fn domain() -> glib::Quark {
glib::Quark::from_string("qemu-gtk4")
}
fn code(self) -> i32 {
self as _
}
fn from(code: i32) -> Option<Self>
where
Self: Sized,
{
use self::AppError::*;
match code {
x if x == GL as i32 => Some(GL),
_ => Some(Failed),
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, glib::GErrorDomain)]
#[gerror_domain(name = "QemuGtk")]
pub enum QemuGtkError {
GL,
Failed,
}