[librsvg: 8/38] check_is_loaded() - Renamed; return a Result instead of a bool



commit 95045d7df5b45ff3db2fb8f85529dc70022831ec
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Jan 22 17:32:24 2019 -0600

    check_is_loaded() - Renamed; return a Result instead of a bool

 rsvg_internals/src/error.rs  |  5 ++++-
 rsvg_internals/src/handle.rs | 24 ++++++++++++------------
 2 files changed, 16 insertions(+), 13 deletions(-)
---
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index b763d1d2..da444f79 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -106,6 +106,7 @@ pub enum RenderingError {
     InvalidHref,
     SvgHasNoSize,
     OutOfMemory,
+    HandleIsNotLoaded,
 }
 
 impl From<cairo::Status> for RenderingError {
@@ -245,6 +246,7 @@ impl error::Error for RenderingError {
             RenderingError::InvalidHref => "invalid href",
             RenderingError::SvgHasNoSize => "svg has no size",
             RenderingError::OutOfMemory => "out of memory",
+            RenderingError::HandleIsNotLoaded => "SVG data is not loaded into handle",
         }
     }
 }
@@ -258,7 +260,8 @@ impl fmt::Display for RenderingError {
             | RenderingError::InstancingLimit
             | RenderingError::InvalidHref
             | RenderingError::SvgHasNoSize
-            | RenderingError::OutOfMemory => write!(f, "{}", self.description()),
+            | RenderingError::OutOfMemory
+            | RenderingError::HandleIsNotLoaded => write!(f, "{}", self.description()),
         }
     }
 }
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 95cde58c..0c0bcbbf 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -721,26 +721,26 @@ pub unsafe extern "C" fn rsvg_handle_rust_set_testing(
     rhandle.is_testing.set(from_glib(testing));
 }
 
-fn is_loaded(handle: &Handle) -> bool {
+fn check_is_loaded(handle: &Handle) -> Result<(), RenderingError> {
     match handle.load_state.get() {
         LoadState::Start => {
             rsvg_g_warning("RsvgHandle has not been loaded");
-            false
+            Err(RenderingError::HandleIsNotLoaded)
         }
 
         LoadState::Loading => {
             rsvg_g_warning("RsvgHandle is still loading; call rsvg_handle_close() first");
-            false
+            Err(RenderingError::HandleIsNotLoaded)
         }
 
-        LoadState::ClosedOk => true,
+        LoadState::ClosedOk => Ok(()),
 
         LoadState::ClosedError => {
             rsvg_g_warning(
                 "RsvgHandle could not read or parse the SVG; did you check for errors during the \
                  loading stage?",
             );
-            false
+            Err(RenderingError::HandleIsNotLoaded)
         }
     }
 }
@@ -820,7 +820,7 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_geometry_sub(
 ) -> glib_sys::gboolean {
     let rhandle = get_rust_handle(handle);
 
-    if !is_loaded(rhandle) {
+    if check_is_loaded(rhandle).is_err() {
         return false.to_glib();
     }
 
@@ -861,7 +861,7 @@ pub unsafe extern "C" fn rsvg_handle_rust_has_sub(
 ) -> glib_sys::gboolean {
     let rhandle = get_rust_handle(handle);
 
-    if !is_loaded(rhandle) {
+    if check_is_loaded(rhandle).is_err() {
         return false.to_glib();
     }
 
@@ -883,7 +883,7 @@ pub unsafe extern "C" fn rsvg_handle_rust_render_cairo_sub(
     let cr = from_glib_none(cr);
     let id: Option<String> = from_glib_none(id);
 
-    if !is_loaded(rhandle) {
+    if check_is_loaded(rhandle).is_err() {
         return false.to_glib();
     }
 
@@ -920,7 +920,7 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_pixbuf_sub(
     let rhandle = get_rust_handle(handle);
     let id: Option<String> = from_glib_none(id);
 
-    if !is_loaded(rhandle) {
+    if check_is_loaded(rhandle).is_err() {
         return ptr::null_mut();
     }
 
@@ -937,7 +937,7 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_dimensions(
 ) {
     let rhandle = get_rust_handle(handle);
 
-    if !is_loaded(rhandle) {
+    if check_is_loaded(rhandle).is_err() {
         return;
     }
 
@@ -967,7 +967,7 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_dimensions_sub(
 ) -> glib_sys::gboolean {
     let rhandle = get_rust_handle(handle);
 
-    if !is_loaded(rhandle) {
+    if check_is_loaded(rhandle).is_err() {
         return false.to_glib();
     }
 
@@ -1001,7 +1001,7 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_position_sub(
 ) -> glib_sys::gboolean {
     let rhandle = get_rust_handle(handle);
 
-    if !is_loaded(rhandle) {
+    if check_is_loaded(rhandle).is_err() {
         return false.to_glib();
     }
 


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