From 101940335cba5b3dd5a7058f829370057c5542b8 Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Wed, 20 Nov 2019 19:56:13 +0100 Subject: [PATCH 1/4] Fix public constructor from miniz_oxide status Avoids leaking the dependency on `miniz_oxide` into the public interface by making a constructor taking a status argument crate internal. It would otherwise not be possible to replace the deflate decoder without breaking that interface. --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 6c6021b..95b3435 100644 --- a/src/error.rs +++ b/src/error.rs @@ -68,7 +68,7 @@ pub struct InflateError { } impl InflateError { - pub fn new(status: TINFLStatus) -> Self { + pub(crate) fn new(status: TINFLStatus) -> Self { Self { status } } } From a14b23473b6171e1ee7ab5310afb50a632cce3da Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Wed, 20 Nov 2019 20:02:55 +0100 Subject: [PATCH 2/4] Export the inflate error publicly It encapsulates the implementation detail of holding a miniz_oxide status within. The derived traits are not too extensive for other possible representations as well. --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8550be3..03ab3e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ pub mod decoder; pub mod encoder; mod error; -pub use self::error::{TiffError, TiffFormatError, TiffResult, TiffUnsupportedError}; +pub use self::error::{InflateError, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError}; /// An enumeration over supported color types and their bit depths #[derive(Copy, PartialEq, Eq, Debug, Clone, Hash)] From 1d9944c5c506d0b7af182bcf6eda23c223bcfa09 Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Wed, 20 Nov 2019 20:58:45 +0100 Subject: [PATCH 3/4] Mark both detailed error types as non-exhaustive This makes it cheaper to introduce new features that might require amending the list of variants by allowing us to introduce previously uncovered causes or more specialized representations. --- src/error.rs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index 95b3435..8705149 100644 --- a/src/error.rs +++ b/src/error.rs @@ -11,19 +11,26 @@ use ColorType; /// Tiff error kinds. #[derive(Debug)] pub enum TiffError { - /// The Image is not formatted properly + /// The Image is not formatted properly. FormatError(TiffFormatError), - /// The Decoder does not support this image format + /// The Decoder does not support features required by the image. UnsupportedError(TiffUnsupportedError), - /// An I/O Error occurred while decoding the image + /// An I/O Error occurred while decoding the image. IoError(io::Error), - /// The Limits of the Decoder is exceeded, + /// The Limits of the Decoder is exceeded. LimitsExceeded, } +/// The image is not formatted properly. +/// +/// The indicate that the encoder producing the image might behave incorrectly or that the input +/// file has been corrupted. +/// +/// The list of variants may grow to incorporate errors of future features. Matching against this +/// exhaustively is not covered by interface stability guarantees. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum TiffFormatError { TiffSignatureNotFound, @@ -36,6 +43,9 @@ pub enum TiffFormatError { UnsignedIntegerExpected(Value), SignedIntegerExpected(Value), InflateError(InflateError), + #[doc(hidden)] + /// Do not match against this variant. It may get removed. + __NonExhaustive, } impl fmt::Display for TiffFormatError { @@ -58,10 +68,12 @@ impl fmt::Display for TiffFormatError { write!(fmt, "Expected signed integer, {:?} found.", val) } InflateError(_) => write!(fmt, "Failed to decode inflate data."), + __NonExhaustive => unreachable!(), } } } +/// Decompression failed due to faulty compressed data. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct InflateError { status: TINFLStatus, @@ -79,6 +91,14 @@ impl TiffError { } } +/// The Decoder does not support features required by the image. +/// +/// This only captures known failures for which the standard either does not require support or an +/// implementation has been planned but not yet completed. Some variants may become unused over +/// time and will then get deprecated before being removed. +/// +/// The list of variants may grow. Matching against this exhaustively is not covered by interface +/// stability guarantees. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum TiffUnsupportedError { HorizontalPredictor(ColorType), @@ -91,6 +111,9 @@ pub enum TiffUnsupportedError { UnsupportedBitsPerChannel(u8), UnsupportedPlanarConfig(Option), UnsupportedDataType, + #[doc(hidden)] + /// Do not match against this variant. It may get removed. + __NonExhaustive, } impl fmt::Display for TiffUnsupportedError { @@ -128,6 +151,7 @@ impl fmt::Display for TiffUnsupportedError { write!(fmt, "Unsupported planar configuration “{:?}”.", config) } UnsupportedDataType => write!(fmt, "Unsupported data type."), + __NonExhaustive => unreachable!(), } } } From f13492e41dad9f682dee0aad9e344418d42d3063 Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Thu, 21 Nov 2019 18:46:55 +0100 Subject: [PATCH 4/4] Fix a doc typo found in PR review --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 8705149..34902fe 100644 --- a/src/error.rs +++ b/src/error.rs @@ -26,7 +26,7 @@ pub enum TiffError { /// The image is not formatted properly. /// -/// The indicate that the encoder producing the image might behave incorrectly or that the input +/// This indicates that the encoder producing the image might behave incorrectly or that the input /// file has been corrupted. /// /// The list of variants may grow to incorporate errors of future features. Matching against this