[librsvg] impl Error for RenderingError



commit 8c79496d13004a553314a729a47b2b1156788e4a
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Jan 11 19:10:31 2019 -0600

    impl Error for RenderingError

 rsvg_internals/src/error.rs | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index 38064761..d0600034 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -91,14 +91,14 @@ impl<'a> From<BasicParseError<'a>> for ValueErrorKind {
     }
 }
 
-#[derive(Clone)]
+#[derive(Debug, Clone)]
 pub enum DefsLookupErrorKind {
     HrefError(HrefError),
     CannotLookupExternalReferences,
     NotFound,
 }
 
-#[derive(Clone)]
+#[derive(Debug, Clone)]
 pub enum RenderingError {
     Cairo(cairo::Status),
     CircularReference,
@@ -203,6 +203,32 @@ impl fmt::Display for LoadingError {
     }
 }
 
+impl error::Error for RenderingError {
+    fn description(&self) -> &str {
+        match *self {
+            RenderingError::Cairo(_) => "cairo error",
+            RenderingError::CircularReference => "circular reference",
+            RenderingError::InstancingLimit => "instancing limit",
+            RenderingError::InvalidId(_) => "invalid id",
+            RenderingError::SvgHasNoSize => "svg has no size",
+            RenderingError::OutOfMemory => "out of memory",
+        }
+    }
+}
+
+impl fmt::Display for RenderingError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match *self {
+            RenderingError::Cairo(ref status) => write!(f, "cairo error: {:?}", status),
+            RenderingError::InvalidId(ref id) => write!(f, "invalid id: {:?}", id),
+            RenderingError::CircularReference
+            | RenderingError::InstancingLimit
+            | RenderingError::SvgHasNoSize
+            | RenderingError::OutOfMemory => write!(f, "{}", self.description()),
+        }
+    }
+}
+
 impl From<cairo::Status> for LoadingError {
     fn from(e: cairo::Status) -> LoadingError {
         assert!(e != cairo::Status::Success);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]