m64_movie/
lib.rs

1#![doc = include_str!("../README.md")]
2#![warn(missing_docs)]
3#![warn(clippy::missing_docs_in_private_items)]
4
5pub mod doc;
6pub mod parsed;
7pub mod raw;
8pub mod shared;
9
10#[doc(inline)]
11pub use parsed::Movie;
12
13#[doc(inline)]
14pub use raw::RawMovie;
15
16/// Error type for [`RawMovie`] operations.
17#[derive(Debug, thiserror::Error)]
18pub enum MovieError {
19    /// Error when reading or writing binary data.
20    #[error("Failed to read movie data: {0}")]
21    BinRWError(#[from] binrw::Error),
22    /// Error when reading or writing files.
23    #[error("Failed to read file: {0}")]
24    FileError(#[from] std::io::Error),
25    /// Error when parsing a [`EncodedFixedStr`](`shared::EncodedFixedStr`).
26    #[error("Failed to parse string: {0}")]
27    FixedStrError(#[from] EncodedFixedStrError),
28    /// Error when parsing a [`Movie`].
29    #[error("Failed to parse movie: {0}")]
30    MovieParseError(#[from] MovieParseError),
31}
32
33/// Error type for [`EncodedFixedStr`](`shared::EncodedFixedStr`) encoding and decoding.
34#[derive(Debug, thiserror::Error)]
35pub enum EncodedFixedStrError {
36    /// Error when the byte slice is not valid UTF-8.
37    #[error("Invalid UTF-8 string: {0}")]
38    Utf8Error(#[from] std::str::Utf8Error),
39    /// Error when the string is not valid ASCII.
40    #[error("Invalid ASCII string: {0}")]
41    InvalidAscii(String),
42    /// Errors related to [`fixedstr::zstr`].
43    #[error("Fixed string error: {0}")]
44    FixedStrError(String),
45}
46
47/// Error type for [`Movie`] parsing errors.
48#[derive(Debug, thiserror::Error)]
49pub enum MovieParseError {
50    /// Error when the movie file has an invalid or unsupported version.
51    #[error("Invalid movie version: {0}")]
52    UnsupportedVersion(u32),
53    /// Error when the movie file has an invalid or unsupported extended version.
54    #[error("Invalid movie extended version: {0}")]
55    UnsupportedExtendedVersion(u8),
56}
57
58/// Extensions for reading binary data.
59pub trait BinReadExt
60where
61    Self: Sized,
62{
63    /// The error type returned by the reading methods.
64    type Error;
65    /// Reads the binary data from a byte slice.
66    fn from_bytes(bytes: &[u8]) -> Result<Self, Self::Error>;
67    /// Reads the binary data from a file.
68    fn from_file<P: AsRef<std::path::Path>>(path: P) -> Result<Self, Self::Error>;
69}
70
71/// Extensions for writing binary data.
72pub trait BinWriteExt {
73    /// The error type returned by the writing methods.
74    type Error;
75    /// Converts the instance to a byte vector.
76    fn to_bytes(&self) -> Result<Vec<u8>, Self::Error>;
77    /// Writes the instance to a binary file.
78    fn to_file<P: AsRef<std::path::Path>>(&self, path: P) -> Result<(), Self::Error>;
79}
80
81/// An enum representing the buttons on a Mupen64 controller.
82#[derive(Debug, Copy, Clone, Eq, PartialEq)]
83pub enum ControllerButton {
84    /// The right directional pad button.
85    DPadRight,
86    /// The left directional pad button.
87    DPadLeft,
88    /// The down directional pad button.
89    DPadDown,
90    /// The up directional pad button.
91    DPadUp,
92    /// The start button.
93    Start,
94    /// The Z button.
95    Z,
96    /// The B button.
97    B,
98    /// The A button.
99    A,
100    /// The C-right button.
101    CRight,
102    /// The C-left button.
103    CLeft,
104    /// The C-down button.
105    CDown,
106    /// The C-up button.
107    CUp,
108    /// The right trigger button.
109    TriggerRight,
110    /// The left trigger button.
111    TriggerLeft,
112    /// Reserved button 01.
113    Reserved01,
114    /// Reserved button 02.
115    Reserved02,
116}