gta_img/
error.rs

1use core::fmt;
2use std::{error::Error, io};
3
4/// Represents a read-related error.
5#[derive(Debug)]
6pub enum ReadError {
7	/// Indicates that a generic I/O error occurred.
8	IoError(io::Error),
9
10	/// Indicates that the header was not in the expected format for the version.
11	InvalidHeader,
12}
13
14/// Represents a write-related error.
15#[derive(Debug)]
16pub enum WriteError {
17	/// Indicates that a generic I/O error occurred.
18	IoError(io::Error),
19
20	/// Indicates that there is insufficient size in the header to add further entries.
21	InsufficientHeaderSize,
22
23	/// Indicates that the provided name of an entry is longer than 23 characters.
24	InvalidNameLength
25}
26
27impl Error for ReadError {}
28impl Error for WriteError {}
29
30impl fmt::Display for ReadError {
31	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32		match self {
33			Self::IoError(err) => write!(f, "input/output error [{}]", err),
34			Self::InvalidHeader => write!(f, "invalid header"),
35		}
36	}
37}
38
39impl fmt::Display for WriteError {
40	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
41		match self {
42			Self::IoError(err) => write!(f, "input/output error [{}]", err),
43			Self::InsufficientHeaderSize => write!(f, "insufficient header size"),
44			Self::InvalidNameLength => write!(f, "invalid name length")
45		}
46	}
47}
48
49impl From<io::Error> for ReadError {
50	fn from(value: io::Error) -> Self {
51		Self::IoError(value)
52	}
53}
54
55impl From<io::Error> for WriteError {
56	fn from(value: io::Error) -> Self {
57		Self::IoError(value)
58	}
59}