From ad72c3783412ebc5ddf131c31968afe1e8f9f730 Mon Sep 17 00:00:00 2001 From: Luracasmus <77991691+Luracasmus@users.noreply.github.com> Date: Wed, 10 Dec 2025 21:00:13 +0100 Subject: [PATCH] Revert "Shrink the `PngError` type" This reverts commit 76c74841b49d0b7a88a0069c7a801f954b7a9f79. --- src/error.rs | 4 ++-- src/lib.rs | 9 +++------ src/png/mod.rs | 3 +-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/error.rs b/src/error.rs index 448d87c2..92937e3f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -15,9 +15,9 @@ pub enum PngError { InvalidData, InvalidDepthForType(BitDepth, ColorType), NotPNG, - ReadFailed(Box, std::io::Error), + ReadFailed(String, std::io::Error), TruncatedData, - WriteFailed(Box, std::io::Error), + WriteFailed(String, std::io::Error), Other(Box), } diff --git a/src/lib.rs b/src/lib.rs index 1b59eb67..a447352d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -257,9 +257,8 @@ pub fn optimize(input: &InFile, output: &OutFile, opts: &Options) -> PngResult<( let output_path = path .as_ref() .map_or_else(|| input.path().unwrap(), PathBuf::as_path); - let out_file = File::create(output_path).map_err(|err| { - PngError::WriteFailed(output_path.display().to_string().into_boxed_str(), err) - })?; + let out_file = File::create(output_path) + .map_err(|err| PngError::WriteFailed(output_path.display().to_string(), err))?; if let Some(metadata_input) = &opt_metadata_preserved { copy_permissions(metadata_input, &out_file)?; } @@ -269,9 +268,7 @@ pub fn optimize(input: &InFile, output: &OutFile, opts: &Options) -> PngResult<( .write_all(&optimized_output) // flush BufWriter so IO errors don't get swallowed silently on close() by drop! .and_then(|()| buffer.flush()) - .map_err(|e| { - PngError::WriteFailed(output_path.display().to_string().into_boxed_str(), e) - })?; + .map_err(|e| PngError::WriteFailed(output_path.display().to_string(), e))?; // force drop and thereby closing of file handle before modifying any timestamp std::mem::drop(buffer); if let Some(metadata_input) = &opt_metadata_preserved { diff --git a/src/png/mod.rs b/src/png/mod.rs index 3dbbed54..f29d583f 100644 --- a/src/png/mod.rs +++ b/src/png/mod.rs @@ -52,8 +52,7 @@ impl PngData { } pub fn read_file(filepath: &Path) -> PngResult> { - fs::read(filepath) - .map_err(|e| PngError::ReadFailed(filepath.display().to_string().into_boxed_str(), e)) + fs::read(filepath).map_err(|e| PngError::ReadFailed(filepath.display().to_string(), e)) } /// Create a new `PngData` struct by reading a slice