From f99ce277daea518169d1503bdc4740365ae3d734 Mon Sep 17 00:00:00 2001 From: Luracasmus <77991691+Luracasmus@users.noreply.github.com> Date: Wed, 10 Dec 2025 23:34:46 +0100 Subject: [PATCH] Use `PngResult` where applicable (#752) --- src/lib.rs | 2 +- src/png/mod.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c09432d3..a447352d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,7 +86,7 @@ impl RawImage { color_type: ColorType, bit_depth: BitDepth, data: Vec, - ) -> Result { + ) -> PngResult { // Validate bit depth let valid_depth = match color_type { ColorType::Grayscale { .. } => true, diff --git a/src/png/mod.rs b/src/png/mod.rs index c1395bb9..f29d583f 100644 --- a/src/png/mod.rs +++ b/src/png/mod.rs @@ -7,7 +7,7 @@ use rgb::ComponentSlice; use rustc_hash::FxHashMap; use crate::{ - Options, + Options, PngResult, apng::*, colors::{BitDepth, ColorType}, deflate, @@ -45,18 +45,18 @@ pub struct PngData { impl PngData { /// Create a new `PngData` struct by opening a file #[inline] - pub fn new(filepath: &Path, opts: &Options) -> Result { + pub fn new(filepath: &Path, opts: &Options) -> PngResult { let byte_data = Self::read_file(filepath)?; Self::from_slice(&byte_data, opts) } - pub fn read_file(filepath: &Path) -> Result, PngError> { + pub fn read_file(filepath: &Path) -> PngResult> { fs::read(filepath).map_err(|e| PngError::ReadFailed(filepath.display().to_string(), e)) } /// Create a new `PngData` struct by reading a slice - pub fn from_slice(byte_data: &[u8], opts: &Options) -> Result { + pub fn from_slice(byte_data: &[u8], opts: &Options) -> PngResult { let mut byte_offset: usize = 0; // Test that png header is valid let header = byte_data.get(0..8).ok_or(PngError::TruncatedData)?; @@ -248,7 +248,7 @@ impl PngData { } impl PngImage { - pub fn new(ihdr: IhdrData, compressed_data: &[u8]) -> Result { + pub fn new(ihdr: IhdrData, compressed_data: &[u8]) -> PngResult { let raw_data = deflate::inflate(compressed_data, ihdr.raw_data_size())?; // Reject files with incorrect width/height or truncated data @@ -332,7 +332,7 @@ impl PngImage { } /// Reverse all filters applied on the image, returning an unfiltered IDAT bytestream - fn unfilter_image(&self) -> Result, PngError> { + fn unfilter_image(&self) -> PngResult> { let mut unfiltered = Vec::with_capacity(self.data.len()); let bpp = self.bytes_per_channel() * self.channels_per_pixel(); let mut last_line: Vec = Vec::new();