1use alloc::string::String;
10use core::fmt::{Debug, Formatter};
11
12use zune_core::bytestream::ZByteIoError;
13
14#[non_exhaustive]
16pub enum BmpDecoderErrors {
17 InvalidMagicBytes,
19 TooSmallBuffer(usize, usize),
22 GenericStatic(&'static str),
24 Generic(String),
26 TooLargeDimensions(&'static str, usize, usize),
29 OverFlowOccurred,
31 IoErrors(ZByteIoError)
32}
33
34impl Debug for BmpDecoderErrors {
35 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
36 match self {
37 Self::InvalidMagicBytes => {
38 writeln!(f, "Invalid magic bytes, file does not start with BM")
39 }
40 Self::TooSmallBuffer(expected, found) => {
41 writeln!(
42 f,
43 "Too small of buffer, expected {} but found {}",
44 expected, found
45 )
46 }
47 Self::GenericStatic(header) => {
48 writeln!(f, "{}", header)
49 }
50 Self::TooLargeDimensions(dimension, expected, found) => {
51 writeln!(
52 f,
53 "Too large dimensions for {dimension} , {found} exceeds {expected}"
54 )
55 }
56 Self::Generic(message) => {
57 writeln!(f, "{}", message)
58 }
59 Self::OverFlowOccurred => {
60 writeln!(f, "Overflow occurred")
61 }
62 Self::IoErrors(err) => {
63 writeln!(f, "{:?}", err)
64 }
65 }
66 }
67}
68
69impl From<ZByteIoError> for BmpDecoderErrors {
70 fn from(value: ZByteIoError) -> Self {
71 BmpDecoderErrors::IoErrors(value)
72 }
73}