Skip to main content

oxideav_tiff/
error.rs

1//! Crate-local error type used by `oxideav-tiff`'s standalone
2//! (no `oxideav-core`) public API.
3//!
4//! Defined as a small std-only enum so the crate can be built with the
5//! default `registry` feature off — i.e. without depending on
6//! `oxideav-core` at all. When the `registry` feature is on (the
7//! default) a `From<TiffError> for oxideav_core::Error` impl is enabled
8//! in [`crate::registry`] so the `Decoder` trait surface still
9//! interoperates cleanly.
10//!
11//! The variants mirror the subset of `oxideav_core::Error` the TIFF
12//! decoder pipeline actually produces.
13
14use core::fmt;
15
16/// Crate-local error type for the TIFF decoder pipeline.
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub enum TiffError {
19    /// Bitstream / IFD / strip layout was malformed.
20    InvalidData(String),
21    /// Bitstream was syntactically valid but uses a feature this crate
22    /// does not implement yet.
23    Unsupported(String),
24}
25
26impl TiffError {
27    /// Construct a [`TiffError::InvalidData`] from a stringy message.
28    pub fn invalid(msg: impl Into<String>) -> Self {
29        Self::InvalidData(msg.into())
30    }
31
32    /// Construct a [`TiffError::Unsupported`] from a stringy message.
33    pub fn unsupported(msg: impl Into<String>) -> Self {
34        Self::Unsupported(msg.into())
35    }
36}
37
38impl fmt::Display for TiffError {
39    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40        match self {
41            Self::InvalidData(s) => write!(f, "invalid data: {s}"),
42            Self::Unsupported(s) => write!(f, "unsupported: {s}"),
43        }
44    }
45}
46
47impl std::error::Error for TiffError {}
48
49/// `Result` alias scoped to `oxideav-tiff`. Standalone (no
50/// `oxideav-core`) callers see this; framework callers convert via the
51/// gated `From<TiffError> for oxideav_core::Error` impl.
52pub type Result<T> = core::result::Result<T, TiffError>;