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.
parent 1761fd56
Pipeline #104692 failed with stages
in 9 minutes and 55 seconds
......@@ -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);
......
......@@ -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
};
......
......@@ -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)]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment