use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DecodedImage {
pub data: Vec<u8>,
pub width: u32,
pub height: u32,
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum DecodeError {
#[error("I/O error: {0}")]
Io(String),
#[error("JPEG error: {0}")]
Jpeg(String),
#[error("Invalid format: {0}")]
InvalidFormat(String),
#[error("Unsupported format: {0}")]
Unsupported(String),
#[error("Buffer too short: expected {expected} bytes, got {actual}")]
BufferTooShort {
expected: usize,
actual: usize,
},
#[error("Profile error: {0}")]
Profile(String),
#[error("Canceled: {0}")]
Canceled(String),
#[error("File too large: {size} bytes exceeds limit of {limit} bytes")]
FileTooLarge {
size: usize,
limit: usize,
},
}
impl fmt::Display for DecodedImage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"DecodedImage {{ data: {} bytes, width: {}, height: {} }}",
self.data.len(),
self.width,
self.height,
)
}
}