1use std::fmt;
2
3#[derive(Debug)]
4pub enum WebpError {
5 UnsupportedFormat,
6
7 InvalidQuality(f32),
8
9 InvalidDimensions { width: u32, height: u32 },
10
11 InvalidBufferLength { expected: usize, actual: usize },
12
13 DecodeJpeg(String),
14
15 DecodePng(String),
16
17 EncodeWebp,
18}
19
20impl fmt::Display for WebpError {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Self::UnsupportedFormat => write!(f, "unsupported input format"),
24 Self::InvalidQuality(quality) => write!(f, "invalid quality: {quality}"),
25 Self::InvalidDimensions { width, height } => {
26 write!(f, "invalid dimensions: {width}x{height}")
27 }
28 Self::InvalidBufferLength { expected, actual } => {
29 write!(
30 f,
31 "invalid buffer length: expected {expected}, got {actual}"
32 )
33 }
34 Self::DecodeJpeg(message) => write!(f, "jpeg decode failed: {message}"),
35 Self::DecodePng(message) => write!(f, "png decode failed: {message}"),
36 Self::EncodeWebp => write!(f, "webp encode failed"),
37 }
38 }
39}
40
41impl std::error::Error for WebpError {}