[librsvg] (#449): librsvg_crate: Make cancellable arguments consistent with gio-rs



commit 1761fd56ab31f9d2196feb9d3f19b30a83078504
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Aug 14 14:23:15 2019 -0500

    (#449): librsvg_crate: Make cancellable arguments consistent with gio-rs
    
    The idea is to "fn foo<P: IsA<Cancellable>>(p: Option<&P>)"
    everywhere.
    
    Fixes https://gitlab.gnome.org/GNOME/librsvg/issues/449

 librsvg_crate/examples/render_to_file.rs |  2 +-
 librsvg_crate/src/lib.rs                 | 19 +++++++------------
 librsvg_crate/tests/utils/mod.rs         |  2 +-
 3 files changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/librsvg_crate/examples/render_to_file.rs b/librsvg_crate/examples/render_to_file.rs
index b7533d20..3dbce400 100644
--- a/librsvg_crate/examples/render_to_file.rs
+++ b/librsvg_crate/examples/render_to_file.rs
@@ -6,7 +6,7 @@ fn main() {
     let bytes = glib::Bytes::from_static(include_bytes!("org.gnome.Epiphany.svg"));
     let stream = gio::MemoryInputStream::new_from_bytes(&bytes);
     let handle = librsvg::Loader::new()
-        .read_stream(&stream, None, None)
+        .read_stream(&stream, None, None::<&gio::Cancellable>)
         .unwrap();
     let renderer = librsvg::CairoRenderer::new(&handle);
 
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index 3ab58117..bdec4e50 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -227,7 +227,7 @@ impl Loader {
     /// ```
     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)
+        self.read_file(&file, None::<&Cancellable>)
     }
 
     /// Reads an SVG file from a `gio::File`.
@@ -245,18 +245,13 @@ impl Loader {
     ///     .read_file(&gio::File::new_for_path("hello.svg"), None)
     ///     .unwrap();
     /// ```
-    pub fn read_file<'a, P: Into<Option<&'a Cancellable>>>(
+    pub fn read_file<P: IsA<Cancellable>>(
         self,
         file: &gio::File,
-        cancellable: P,
+        cancellable: Option<&P>,
     ) -> Result<SvgHandle, LoadingError> {
-        let cancellable = cancellable.into();
-
-        let cancellable_clone = cancellable.clone();
-
         let stream = file.read(cancellable)?;
-
-        self.read_stream(&stream, Some(&file), cancellable_clone)
+        self.read_stream(&stream, Some(&file), cancellable)
     }
 
     /// Reads an SVG stream from a `gio::InputStream`.
@@ -271,11 +266,11 @@ impl Loader {
     /// URL where this SVG got loaded from.
     ///
     /// The `cancellable` can be used to cancel loading from another thread.
-    pub fn read_stream<'a, P: Into<Option<&'a Cancellable>>, S: IsA<gio::InputStream>>(
+    pub fn read_stream<S: IsA<gio::InputStream>, P: IsA<Cancellable>>(
         self,
         stream: &S,
         base_file: Option<&gio::File>,
-        cancellable: P,
+        cancellable: Option<&P>,
     ) -> Result<SvgHandle, LoadingError> {
         let base_url = if let Some(base_file) = base_file {
             Some(url_from_file(&base_file)?)
@@ -290,7 +285,7 @@ impl Loader {
         Ok(SvgHandle(Handle::from_stream(
             &load_options,
             stream,
-            cancellable.into(),
+            cancellable.map(|c| c.as_ref()),
         )?))
     }
 }
diff --git a/librsvg_crate/tests/utils/mod.rs b/librsvg_crate/tests/utils/mod.rs
index f188a3f3..b1bb4a06 100644
--- a/librsvg_crate/tests/utils/mod.rs
+++ b/librsvg_crate/tests/utils/mod.rs
@@ -23,7 +23,7 @@ pub fn load_svg(input: &'static [u8]) -> SvgHandle {
     let bytes = glib::Bytes::from_static(input);
     let stream = gio::MemoryInputStream::new_from_bytes(&bytes);
 
-    Loader::new().read_stream(&stream, None, None).unwrap()
+    Loader::new().read_stream(&stream, None, None::<&gio::Cancellable>).unwrap()
 }
 
 #[derive(Copy, Clone)]


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