[librsvg] handle: cleanup close



commit fa570e9a0a023eb4e3a1f300d6135fbe85d95037
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Jan 13 16:59:07 2019 +0100

    handle: cleanup close
    
    Make code more idiomatic and remove need for helper function

 rsvg_internals/src/handle.rs | 17 +++++++----------
 rsvg_internals/src/load.rs   | 10 ++++++----
 2 files changed, 13 insertions(+), 14 deletions(-)
---
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index fa7d2b6a..4eec6f9a 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -247,9 +247,14 @@ impl Handle {
             }
 
             LoadState::Loading => self
-                .close_internal()
-                .and_then(|_| {
+                .load
+                .borrow_mut()
+                .as_mut()
+                .unwrap()
+                .close()
+                .and_then(|mut xml| {
                     self.load_state.set(LoadState::ClosedOk);
+                    *self.svg.borrow_mut() = Some(Rc::new(xml.steal_result()?));
                     Ok(())
                 })
                 .map_err(|e| {
@@ -271,14 +276,6 @@ impl Handle {
         res
     }
 
-    fn close_internal(&mut self) -> Result<(), LoadingError> {
-        let mut r = self.load.borrow_mut();
-        let mut load = r.take().unwrap();
-        let mut xml = load.close()?;
-        *self.svg.borrow_mut() = Some(Rc::new(xml.steal_result()?));
-        Ok(())
-    }
-
     fn create_drawing_ctx_for_node(
         &mut self,
         cr: &cairo::Context,
diff --git a/rsvg_internals/src/load.rs b/rsvg_internals/src/load.rs
index ae38a07a..94f30f35 100644
--- a/rsvg_internals/src/load.rs
+++ b/rsvg_internals/src/load.rs
@@ -1,9 +1,10 @@
 use gio;
 use glib::{Bytes, Cast};
 
+use error::LoadingError;
 use handle::{LoadFlags, LoadOptions};
 use xml::XmlState;
-use xml2_load::{xml_state_load_from_possibly_compressed_stream, ParseFromStreamError};
+use xml2_load::xml_state_load_from_possibly_compressed_stream;
 
 // Long-lived loading context for the deprecated I/O API
 //
@@ -53,7 +54,7 @@ impl LoadContext {
         self.buffer.extend_from_slice(buf);
     }
 
-    pub fn close(&mut self) -> Result<XmlState, ParseFromStreamError> {
+    pub fn close(&mut self) -> Result<XmlState, LoadingError> {
         let state = self.state;
 
         match state {
@@ -73,8 +74,9 @@ impl LoadContext {
                     self.load_flags,
                     &stream.upcast(),
                     None,
-                )
-                .and_then(|_| Ok(self.xml.take().unwrap()))
+                )?;
+
+                Ok(self.xml.take().unwrap())
             }
 
             LoadState::Closed => unreachable!(),


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