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::{Rgba, RgbaImage, DynamicImage};
18use std::{
19 error::Error,
20 fmt::{Display, Formatter},
21};
22
23pub type Result<T> = std::result::Result<T, Ra2Error>;
25
26#[derive(Debug)]
28pub enum Ra2Error {
29 IoError(std::io::Error),
31
32 CryptoError {
34 message: String,
36 },
37
38 InvalidFormat {
40 message: String,
42 },
43 EncodeError {
45 format: String,
47 message: String,
49 },
50 DecodeError {
52 format: String,
54 message: String,
56 },
57 FileNotFound(String),
59}
60
61impl Error for Ra2Error {}
62
63impl Display for Ra2Error {
64 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
65 match self {
66 Ra2Error::IoError(e) => {
67 write!(f, "IO error: {}", e)
68 }
69 Ra2Error::CryptoError { message: e } => {
70 write!(f, "Crypto error:: {}", e)
71 }
72 Ra2Error::InvalidFormat { message: e } => {
73 write!(f, "Invalid file format: {}", e)
74 }
75 Ra2Error::FileNotFound(e) => {
76 write!(f, "File not found: {}", e)
77 }
78 Ra2Error::DecodeError { format, message } => {
79 write!(f, "Decode error: {}: {}", format, message)
80 }
81 Ra2Error::EncodeError { format, message } => {
82 write!(f, "Encode error: {}: {}", format, message)
83 }
84 }
85 }
86}