[librsvg/wip/rust-api: 4/5] LoadOptions: add a read_file() method



commit e04893e95af50ae221fd5389b4b18bea625dfd63
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Feb 18 10:53:00 2019 -0600

    LoadOptions: add a read_file() method

 librsvg_crate/src/lib.rs | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index a2880f59..17c92d10 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -8,7 +8,7 @@ extern crate url;
 use std::io::Read;
 use std::path::Path;
 
-use gio::FileExt;
+use gio::{Cancellable, FileExt};
 use glib::object::Cast;
 
 use rsvg_internals::{Dpi, Handle, LoadFlags};
@@ -77,19 +77,26 @@ impl LoadOptions {
 
     pub fn read_path<P: AsRef<Path>>(self, path: P) -> Result<SvgHandle, LoadingError> {
         let file = gio::File::new_for_path(path);
+        self.read_file(&file, None)
+    }
+
+    pub fn read(self, _r: &dyn Read, _base_url: Option<&Url>) -> Result<SvgHandle, LoadingError> {
+        // This requires wrapping a Read with a GInputStream
+        unimplemented!();
+    }
 
+    pub fn read_file<'a, P: Into<Option<&'a Cancellable>>>(
+        self,
+        file: &gio::File,
+        cancellable: P,
+    ) -> Result<SvgHandle, LoadingError> {
         let stream = file.read(None)?;
 
         let mut handle = Handle::new_with_flags(self.load_flags());
-        handle.construct_read_stream_sync(&stream.upcast(), Some(&file), None)?;
+        handle.construct_read_stream_sync(&stream.upcast(), Some(&file), cancellable.into())?;
 
         Ok(SvgHandle(handle))
     }
-
-    pub fn read(self, _r: &dyn Read, _base_url: Option<&Url>) -> Result<SvgHandle, LoadingError> {
-        // This requires wrapping a Read with a GInputStream
-        unimplemented!();
-    }
 }
 
 pub struct SvgHandle(Handle);


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