[librsvg] librsvg_crate: Take all gio arguments as IsA<SomeGioType> generics
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] librsvg_crate: Take all gio arguments as IsA<SomeGioType> generics
- Date: Wed, 14 Aug 2019 19:46:25 +0000 (UTC)
commit 710172f009e6163d87f639240f49af8d4722f143
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Aug 14 14:45:30 2019 -0500
librsvg_crate: Take all gio arguments as IsA<SomeGioType> generics
This lets the caller avoid conversions; we'll do the conversions
internally to concrete types.
librsvg_crate/examples/render_to_file.rs | 2 +-
librsvg_crate/src/lib.rs | 16 +++++++++-------
librsvg_crate/tests/utils/mod.rs | 2 +-
3 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/librsvg_crate/examples/render_to_file.rs b/librsvg_crate/examples/render_to_file.rs
index 3dbce400..4976460a 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::<&gio::Cancellable>)
+ .read_stream(&stream, None::<&gio::File>, 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 bdec4e50..b85fc24f 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -242,16 +242,16 @@ impl Loader {
/// use librsvg::Loader;
///
/// let svg_handle = Loader::new()
- /// .read_file(&gio::File::new_for_path("hello.svg"), None)
+ /// .read_file(&gio::File::new_for_path("hello.svg"), None::<&gio::Cancellable>)
/// .unwrap();
/// ```
- pub fn read_file<P: IsA<Cancellable>>(
+ pub fn read_file<F: IsA<gio::File>, P: IsA<Cancellable>>(
self,
- file: &gio::File,
+ file: &F,
cancellable: Option<&P>,
) -> Result<SvgHandle, LoadingError> {
let stream = file.read(cancellable)?;
- self.read_stream(&stream, Some(&file), cancellable)
+ self.read_stream(&stream, Some(file), cancellable)
}
/// Reads an SVG stream from a `gio::InputStream`.
@@ -266,14 +266,16 @@ impl Loader {
/// URL where this SVG got loaded from.
///
/// The `cancellable` can be used to cancel loading from another thread.
- pub fn read_stream<S: IsA<gio::InputStream>, P: IsA<Cancellable>>(
+ pub fn read_stream<S: IsA<gio::InputStream>, F: IsA<gio::File>, P: IsA<Cancellable>>(
self,
stream: &S,
- base_file: Option<&gio::File>,
+ base_file: Option<&F>,
cancellable: Option<&P>,
) -> Result<SvgHandle, LoadingError> {
+ let base_file = base_file.map(|f| f.as_ref());
+
let base_url = if let Some(base_file) = base_file {
- Some(url_from_file(&base_file)?)
+ Some(url_from_file(base_file)?)
} else {
None
};
diff --git a/librsvg_crate/tests/utils/mod.rs b/librsvg_crate/tests/utils/mod.rs
index b1bb4a06..c76d1223 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::<&gio::Cancellable>).unwrap()
+ Loader::new().read_stream(&stream, None::<&gio::File>, None::<&gio::Cancellable>).unwrap()
}
#[derive(Copy, Clone)]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]