use crate::signatures::Signature;
#[derive(thiserror::Error, Debug, PartialEq)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
HeaderParseError(#[from] HeaderParseError),
#[error(transparent)]
ParseError(#[from] ParseError),
#[error(transparent)]
InvalidCmmError(#[from] InvalidCmmError),
#[error("Invalid CMM: {0}")]
InvalidCmm(&'static str),
#[error("Invalid ICC Profile signature: {0}")]
InvalidPcsTag(Signature),
#[error("Is not a {0}")]
IsNotA(&'static str),
#[error("This is not a valid ICC profile")]
InvalidICCProfile,
#[error("Invalid date/time in ICC profile header: {0}")]
InvalidDate(String),
#[error("Unsupported parametric curve parameter count: {0} (must be 1, 3, 4, 5, or 7)")]
UnsupportedParameterCount(usize),
#[error("Profile exceeds maximum ICC size of 4 GiB ({0} bytes)")]
ProfileTooLarge(usize),
}
macro_rules! define_string_error {
($name:ident, $msg:literal) => {
#[derive(thiserror::Error, Debug, PartialEq)]
#[error($msg)]
pub struct $name(pub String);
impl $name {
pub fn new<T: Into<String>>(msg: T) -> Self {
$name(msg.into())
}
}
impl From<&str> for $name {
fn from(s: &str) -> Self {
$name(s.to_string())
}
}
};
}
define_string_error!(HeaderParseError, "Could not parse ICC Profile header: {0}");
define_string_error!(ParseError, "String parse error: {0}");
define_string_error!(InvalidCmmError, "Invalid CMM: {0}");