1#![deny(missing_debug_implementations, missing_copy_implementations)]
2#![warn(missing_docs, rustdoc::missing_crate_level_docs)]
3#![doc = include_str!("../readme.md")]
4#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/208321371")]
5#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/208321371")]
6
7mod errors;
13mod games;
14
15pub use crate::games::CncGame;
16#[cfg(feature = "image")]
17pub use image::{DynamicImage, Rgba, RgbaImage};
18#[cfg(feature = "apng")]
19pub use apng;
20use std::{
21 error::Error,
22 fmt::{Display, Formatter},
23};
24
25pub type Result<T> = std::result::Result<T, Ra2Error>;
27
28#[derive(Debug)]
30pub enum Ra2Error {
31 IoError(std::io::Error),
33
34 CryptoError {
36 message: String,
38 },
39 InvalidFormat {
41 message: String,
43 },
44 EncodeError {
46 format: String,
48 message: String,
50 },
51 DecodeError {
53 format: String,
55 message: String,
57 },
58 FileNotFound(String),
60 OutOfBoundary {
62 limit: usize,
64 message: String,
66 },
67}
68
69impl Error for Ra2Error {}
70
71impl Display for Ra2Error {
72 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
73 match self {
74 Ra2Error::IoError(e) => {
75 write!(f, "IO error: {}", e)
76 }
77 Ra2Error::CryptoError { message: e } => {
78 write!(f, "Crypto error:: {}", e)
79 }
80 Ra2Error::InvalidFormat { message: e } => {
81 write!(f, "Invalid file format: {}", e)
82 }
83 Ra2Error::FileNotFound(e) => {
84 write!(f, "File not found: {}", e)
85 }
86 Ra2Error::DecodeError { format, message } => {
87 write!(f, "Decode error: {}: {}", format, message)
88 }
89 Ra2Error::EncodeError { format, message } => {
90 write!(f, "Encode error: {}: {}", format, message)
91 }
92 Ra2Error::OutOfBoundary { limit, message } => {
93 write!(f, "Out of boundary {}: {}", limit, message)
94 }
95 }
96 }
97}