Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #364 from EPashkin/error_domain_quark
Browse files Browse the repository at this point in the history
Error domain quark
  • Loading branch information
GuillaumeGomez committed Jul 29, 2018
2 parents 2326b65 + 5585843 commit 219f04a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gir
Submodule gir updated 1 files
+3 −3 src/codegen/enums.rs
6 changes: 3 additions & 3 deletions src/auto/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use Quark;
use error::ErrorDomain;
use ffi;
use ffi as glib_ffi;
use translate::*;

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -214,8 +214,8 @@ impl FromGlib<ffi::GKeyFileError> for KeyFileError {
}

impl ErrorDomain for KeyFileError {
fn domain() -> glib_ffi::GQuark {
unsafe { ffi::g_key_file_error_quark() }
fn domain() -> Quark {
unsafe { from_glib(ffi::g_key_file_error_quark()) }
}

fn code(self) -> i32 {
Expand Down
2 changes: 1 addition & 1 deletion src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 800fb8f)
Generated by gir (https://github.com/gtk-rs/gir @ bec7561)
from gir-files (https://github.com/gtk-rs/gir-files @ b8f5ef1)
9 changes: 5 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! `Error` binding and helper trait.

use std::ffi::CStr;
use Quark;
use std::error;
use std::fmt;
use std::str;
Expand Down Expand Up @@ -33,13 +34,13 @@ impl Error {
pub fn new<T: ErrorDomain>(error: T, message: &str) -> Error {
unsafe {
from_glib_full(
glib_ffi::g_error_new_literal(T::domain(), error.code(), message.to_glib_none().0))
glib_ffi::g_error_new_literal(T::domain().to_glib(), error.code(), message.to_glib_none().0))
}
}

/// Checks if the error domain matches `T`.
pub fn is<T: ErrorDomain>(&self) -> bool {
self.0.domain == T::domain()
self.0.domain == T::domain().to_glib()
}

/// Tries to convert to a specific error enum.
Expand Down Expand Up @@ -67,7 +68,7 @@ impl Error {
/// }
/// ```
pub fn kind<T: ErrorDomain>(&self) -> Option<T> {
if self.0.domain == T::domain() {
if self.0.domain == T::domain().to_glib() {
T::from(self.0.code)
}
else {
Expand Down Expand Up @@ -110,7 +111,7 @@ pub trait ErrorDomain: Copy {
/// Returns the quark identifying the error domain.
///
/// As returned from `g_some_error_quark`.
fn domain() -> glib_ffi::GQuark;
fn domain() -> Quark;

/// Gets the integer representation of the variant.
fn code(self) -> i32;
Expand Down
6 changes: 4 additions & 2 deletions src/file_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

use error::ErrorDomain;
use Quark;
use ffi as glib_ffi;
use translate::from_glib;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FileError {
Expand Down Expand Up @@ -35,8 +37,8 @@ pub enum FileError {
}

impl ErrorDomain for FileError {
fn domain() -> glib_ffi::GQuark {
unsafe { glib_ffi::g_file_error_quark() }
fn domain() -> Quark {
unsafe { from_glib(glib_ffi::g_file_error_quark()) }
}

fn code(self) -> i32 {
Expand Down

0 comments on commit 219f04a

Please sign in to comment.