[librsvg: 9/18] error.rs: Add an empty RsvgError and impl glib::error:ErrorDomain for it
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 9/18] error.rs: Add an empty RsvgError and impl glib::error:ErrorDomain for it
- Date: Fri, 23 Nov 2018 22:32:15 +0000 (UTC)
commit 1a249da88f030f9b88b325afc7953d18f7917636
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Nov 23 10:59:52 2018 -0600
error.rs: Add an empty RsvgError and impl glib::error:ErrorDomain for it
We will use this to call glib::Error::new(). Unfortunately we don't
have detailed error codes in the public API; maybe this can change later.
rsvg_internals/src/error.rs | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
---
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index 5e5505ea..93c111b5 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -4,6 +4,7 @@ use std::fmt;
use cairo;
use cssparser::BasicParseError;
use glib;
+use glib::error::ErrorDomain;
use glib::translate::*;
use glib_sys;
use libc;
@@ -161,3 +162,32 @@ pub fn is_value_error<T>(r: &Result<T, ValueErrorKind>) -> bool {
_ => false,
}
}
+
+/// Used as a generic error to translate to glib::Error
+///
+/// This type implements `glib::error::ErrorDomain`, so it can be used
+/// to obtain the error code while calling `glib::Error::new()`. Unfortunately
+/// the public librsvg API does not have detailed error codes yet, so we use
+/// this single value as the only possible error code to return.
+#[derive(Copy, Clone)]
+pub struct RsvgError;
+
+// Keep in sync with rsvg.h:RsvgError
+const RSVG_ERROR_FAILED: i32 = 0;
+
+impl ErrorDomain for RsvgError {
+ fn domain() -> glib::Quark {
+ from_glib(unsafe { rsvg_error_quark() })
+ }
+
+ fn code(self) -> i32 {
+ RSVG_ERROR_FAILED
+ }
+
+ fn from(code: i32) -> Option<Self> {
+ match code {
+ // We don't have enough information from glib error codes
+ _ => Some(RsvgError)
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]