From b8cad96d145ba32b978e71464a3ac24401210978 Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Mon, 5 Oct 2020 21:54:16 +0200 Subject: [PATCH] Deprecate compound input fn in favor of Reader --- src/dynimage.rs | 24 +++++++++++++++--------- src/lib.rs | 2 ++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/dynimage.rs b/src/dynimage.rs index 987b933644..6852ddb390 100644 --- a/src/dynimage.rs +++ b/src/dynimage.rs @@ -988,12 +988,13 @@ fn image_to_bytes(image: &DynamicImage) -> Vec { /// content before its path. /// /// [`io::Reader`]: io/struct.Reader.html +#[deprecated = "Use `io::Reader`, it combines input functions in more flexible and consistent interface."] pub fn open

(path: P) -> ImageResult where P: AsRef, { - // thin wrapper function to strip generics before calling open_impl - free_functions::open_impl(path.as_ref()) + crate::io::Reader::open(path)? + .decode() } /// Read the dimensions of the image located at the specified path. @@ -1003,12 +1004,13 @@ where /// content before its path or manually supplying the format. /// /// [`io::Reader`]: io/struct.Reader.html +#[deprecated = "Use `io::Reader`, it combines input functions in more flexible and consistent interface."] pub fn image_dimensions

(path: P) -> ImageResult<(u32, u32)> where P: AsRef, { - // thin wrapper function to strip generics before calling open_impl - free_functions::image_dimensions_impl(path.as_ref()) + crate::io::Reader::open(path)? + .into_dimensions() } /// Saves the supplied buffer to a file at the path specified. @@ -1063,9 +1065,12 @@ where /// Try [`io::Reader`] for more advanced uses. /// /// [`io::Reader`]: io/struct.Reader.html +#[deprecated = "Use `io::Reader`, it combines input functions in more flexible and consistent interface."] pub fn load_from_memory(buffer: &[u8]) -> ImageResult { - let format = free_functions::guess_format(buffer)?; - load_from_memory_with_format(buffer, format) + let b = io::Cursor::new(buffer); + crate::io::Reader::new(b) + .with_guessed_format()? + .decode() } /// Create a new image from a byte slice @@ -1078,9 +1083,10 @@ pub fn load_from_memory(buffer: &[u8]) -> ImageResult { /// [`load`]: fn.load.html /// [`io::Reader`]: io/struct.Reader.html #[inline(always)] -pub fn load_from_memory_with_format(buf: &[u8], format: ImageFormat) -> ImageResult { - let b = io::Cursor::new(buf); - free_functions::load(b, format) +#[deprecated = "Use `io::Reader`, it combines input functions in more flexible and consistent interface."] +pub fn load_from_memory_with_format(buffer: &[u8], format: ImageFormat) -> ImageResult { + let b = io::Cursor::new(buffer); + crate::io::Reader::with_format(b, format).decode() } /// Calculates the width and height an image should be resized to. diff --git a/src/lib.rs b/src/lib.rs index 83aec45d0d..4c95008ebb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,6 +126,7 @@ #![cfg_attr(all(test, feature = "benchmarks"), feature(test))] // it's a bit of a pain otherwise #![allow(clippy::many_single_char_names)] +#![cfg_attr(test, allow(deprecated))] #[cfg(all(test, feature = "benchmarks"))] extern crate test; @@ -170,6 +171,7 @@ pub use crate::traits::{EncodableLayout, Primitive, Pixel}; // Opening and loading images pub use crate::io::free_functions::{guess_format, load}; +#[allow(deprecated)] pub use crate::dynimage::{load_from_memory, load_from_memory_with_format, open, save_buffer, save_buffer_with_format, image_dimensions};