[librsvg: 10/16] Use a IsA<gio::InputStream> generic only in the toplevel librsvg_crate API



commit e0beb49179d5a4b4752580e7c924c97eaf46eaef
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Oct 11 10:35:13 2019 -0500

    Use a IsA<gio::InputStream> generic only in the toplevel librsvg_crate API
    
    Don't use generics everywhere; obtain the abstract type as early as
    possible so that the toplevel-internal rsvg_internals::Handle can use
    simply &gio::InputStream arguments.

 librsvg/pixbuf_utils.rs         |  2 +-
 librsvg_crate/src/lib.rs        |  2 +-
 rsvg_internals/src/handle.rs    |  6 +++---
 rsvg_internals/src/io.rs        |  6 +++---
 rsvg_internals/src/svg.rs       |  5 ++---
 rsvg_internals/src/xml.rs       | 13 ++++++-------
 rsvg_internals/src/xml2_load.rs |  7 +++----
 7 files changed, 19 insertions(+), 22 deletions(-)
---
diff --git a/librsvg/pixbuf_utils.rs b/librsvg/pixbuf_utils.rs
index 5c452d32..e34bbed7 100644
--- a/librsvg/pixbuf_utils.rs
+++ b/librsvg/pixbuf_utils.rs
@@ -195,7 +195,7 @@ fn pixbuf_from_file_with_size_mode(
         let handle = match file
             .read(cancellable)
             .map_err(|e| LoadingError::from(e))
-            .and_then(|stream| Handle::from_stream(&load_options, &stream, None))
+            .and_then(|stream| Handle::from_stream(&load_options, stream.as_ref(), None))
         {
             Ok(handle) => handle,
             Err(e) => {
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index b85fc24f..207900fb 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -286,7 +286,7 @@ impl Loader {
 
         Ok(SvgHandle(Handle::from_stream(
             &load_options,
-            stream,
+            stream.as_ref(),
             cancellable.map(|c| c.as_ref()),
         )?))
     }
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index b3e91331..6eeff69f 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -4,7 +4,7 @@ use std::rc::Rc;
 
 use cairo::{self, ImageSurface, Status};
 use gio;
-use glib::{self, IsA};
+use glib;
 use libc;
 use locale_config::{LanguageRange, Locale};
 
@@ -180,9 +180,9 @@ pub struct Handle {
 }
 
 impl Handle {
-    pub fn from_stream<S: IsA<gio::InputStream>>(
+    pub fn from_stream(
         load_options: &LoadOptions,
-        stream: &S,
+        stream: &gio::InputStream,
         cancellable: Option<&gio::Cancellable>,
     ) -> Result<Handle, LoadingError> {
         Ok(Handle {
diff --git a/rsvg_internals/src/io.rs b/rsvg_internals/src/io.rs
index 69702333..13b51b11 100644
--- a/rsvg_internals/src/io.rs
+++ b/rsvg_internals/src/io.rs
@@ -13,7 +13,7 @@ use gio::{
     ZlibCompressorFormat,
     ZlibDecompressor,
 };
-use glib::{self, Bytes as GBytes, Cast, IsA};
+use glib::{self, Bytes as GBytes, Cast};
 
 use crate::allowed_url::AllowedUrl;
 use crate::error::{LoadingError, RsvgError};
@@ -51,8 +51,8 @@ fn decode_data_uri(uri: &str) -> Result<BinaryData, LoadingError> {
 const GZ_MAGIC_0: u8 = 0x1f;
 const GZ_MAGIC_1: u8 = 0x8b;
 
-pub fn get_input_stream_for_loading<S: IsA<InputStream>>(
-    stream: &S,
+pub fn get_input_stream_for_loading(
+    stream: &InputStream,
     cancellable: Option<&Cancellable>,
 ) -> Result<InputStream, glib::Error> {
     // detect gzipped streams (svgz)
diff --git a/rsvg_internals/src/svg.rs b/rsvg_internals/src/svg.rs
index f4a55238..e23f1764 100644
--- a/rsvg_internals/src/svg.rs
+++ b/rsvg_internals/src/svg.rs
@@ -1,6 +1,5 @@
 use gdk_pixbuf::{PixbufLoader, PixbufLoaderExt};
 use gio;
-use glib::IsA;
 use std::cell::RefCell;
 use std::collections::hash_map::Entry;
 use std::collections::HashMap;
@@ -53,9 +52,9 @@ impl Svg {
         }
     }
 
-    pub fn load_from_stream<S: IsA<gio::InputStream>>(
+    pub fn load_from_stream(
         load_options: &LoadOptions,
-        stream: &S,
+        stream: &gio::InputStream,
         cancellable: Option<&gio::Cancellable>,
     ) -> Result<Svg, LoadingError> {
         xml_load_from_possibly_compressed_stream(load_options, stream, cancellable)
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index dbcc8547..7a866145 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -1,7 +1,6 @@
 use crate::xml_rs::{reader::XmlEvent, ParserConfig};
 use encoding::label::encoding_from_whatwg_label;
 use encoding::DecoderTrap;
-use glib::IsA;
 use libc;
 use markup5ever::{local_name, LocalName};
 use std::collections::HashMap;
@@ -473,7 +472,7 @@ impl XmlState {
         })?;
 
         // FIXME: pass a cancellable
-        self.parse_from_stream(stream, None).map_err(|e| match e {
+        self.parse_from_stream(&stream, None).map_err(|e| match e {
             ParseFromStreamError::CouldNotCreateXmlParser => AcquireError::FatalError,
             ParseFromStreamError::IoError(_) => AcquireError::ResourceError,
             ParseFromStreamError::XmlParseError(_) => AcquireError::FatalError,
@@ -484,9 +483,9 @@ impl XmlState {
     //
     // This can be called "in the middle" of an XmlState's processing status,
     // for example, when including another XML file via xi:include.
-    fn parse_from_stream<S: IsA<gio::InputStream>>(
+    fn parse_from_stream(
         &mut self,
-        stream: S,
+        stream: &gio::InputStream,
         cancellable: Option<&gio::Cancellable>,
     ) -> Result<(), ParseFromStreamError> {
         Xml2Parser::from_stream(self, self.load_options.unlimited_size, stream, cancellable)
@@ -549,9 +548,9 @@ fn parse_xml_stylesheet_processing_instruction(data: &str) -> Result<Vec<(String
     unreachable!();
 }
 
-pub fn xml_load_from_possibly_compressed_stream<S: IsA<gio::InputStream>>(
+pub fn xml_load_from_possibly_compressed_stream(
     load_options: &LoadOptions,
-    stream: &S,
+    stream: &gio::InputStream,
     cancellable: Option<&gio::Cancellable>,
 ) -> Result<Svg, LoadingError> {
     let mut xml = XmlState::new(load_options);
@@ -559,7 +558,7 @@ pub fn xml_load_from_possibly_compressed_stream<S: IsA<gio::InputStream>>(
     let stream = get_input_stream_for_loading(stream, cancellable)
         .map_err(|e| ParseFromStreamError::IoError(e))?;
 
-    xml.parse_from_stream(stream, cancellable)?;
+    xml.parse_from_stream(&stream, cancellable)?;
 
     xml.steal_result()
 }
diff --git a/rsvg_internals/src/xml2_load.rs b/rsvg_internals/src/xml2_load.rs
index 01b4bdcd..bd63b131 100644
--- a/rsvg_internals/src/xml2_load.rs
+++ b/rsvg_internals/src/xml2_load.rs
@@ -3,7 +3,6 @@
 
 use gio;
 use gio::prelude::*;
-use glib::prelude::*;
 use std::borrow::Cow;
 use std::cell::RefCell;
 use std::mem;
@@ -320,10 +319,10 @@ pub struct Xml2Parser {
 }
 
 impl Xml2Parser {
-    pub fn from_stream<S: IsA<gio::InputStream>>(
+    pub fn from_stream(
         xml: &mut XmlState,
         unlimited_size: bool,
-        stream: S,
+        stream: &gio::InputStream,
         cancellable: Option<&gio::Cancellable>,
     ) -> Result<Xml2Parser, ParseFromStreamError> {
         init_libxml2();
@@ -338,7 +337,7 @@ impl Xml2Parser {
         let gio_error = Rc::new(RefCell::new(None));
 
         let ctx = Box::new(StreamCtx {
-            stream: stream.upcast(),
+            stream: stream.clone(),
             cancellable: cancellable.map(|c| c.clone()),
             gio_error: gio_error.clone(),
         });


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