ra2_types/
lib.rs

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
7//! RA2 MIX file format library
8//!
9//! This library provides functionality for reading and writing Red Alert 2 MIX files.
10//! It supports both encrypted and unencrypted MIX files, and can extract files from MIX archives.
11
12mod 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
23/// Result type for RA2 MIX file operations
24pub type Result<T> = std::result::Result<T, Ra2Error>;
25
26/// Error type for RA2 MIX file operations
27#[derive(Debug)]
28pub enum Ra2Error {
29    /// IO error
30    IoError(std::io::Error),
31
32    /// Crypto error
33    CryptoError {
34        /// The error message
35        message: String,
36    },
37
38    /// Invalid file format
39    InvalidFormat {
40        /// The error message
41        message: String,
42    },
43    /// Encode error
44    EncodeError {
45        /// The error format
46        format: String,
47        /// The error message
48        message: String,
49    },
50    /// Decode error
51    DecodeError {
52        /// The error format
53        format: String,
54        /// The error message
55        message: String,
56    },
57    /// Missing file
58    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}