ktx2/
error.rs

1use core::fmt;
2#[cfg(feature = "std")]
3use std::error::Error;
4
5/// Error, that happened when data doesn't satisfy expected parameters.
6#[derive(Debug)]
7#[non_exhaustive]
8pub enum ParseError {
9    /// Unexpected magic numbers
10    BadMagic,
11    /// Zero pixel width
12    ZeroWidth,
13    /// Zero face count
14    ZeroFaceCount,
15    /// Data Format Descriptor had an invalid sample bit length.
16    InvalidSampleBitLength,
17    /// Unexpected end of buffer
18    UnexpectedEnd,
19}
20
21#[cfg(feature = "std")]
22impl Error for ParseError {}
23
24impl fmt::Display for ParseError {
25    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26        match &self {
27            ParseError::BadMagic => f.pad("unexpected magic numbers"),
28            ParseError::ZeroWidth => f.pad("zero pixel width"),
29            ParseError::ZeroFaceCount => f.pad("zero face count"),
30            ParseError::InvalidSampleBitLength => f.pad("invalid sample bit length"),
31            ParseError::UnexpectedEnd => f.pad("unexpected end of buffer"),
32        }
33    }
34}