rich_sdl2_rust/
error.rs

1use static_assertions::assert_impl_all;
2
3/// An error occurred from SDL2.
4#[derive(Debug, Clone)]
5#[non_exhaustive]
6pub enum SdlError {
7    /// The feature is unsupported on the platform.
8    UnsupportedFeature,
9    /// There is no free memory.
10    OutOfMemory,
11    /// There is other reasons.
12    Others {
13        /// The message describing reasons.
14        msg: String,
15    },
16}
17
18assert_impl_all!(SdlError: Send, Sync);
19
20/// A specialized [`std::result::Result`] type for this crate.
21pub type Result<T> = std::result::Result<T, SdlError>;
22
23impl std::fmt::Display for SdlError {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        match self {
26            SdlError::UnsupportedFeature => f.write_str("the feature is unsupported"),
27            SdlError::OutOfMemory => f.write_str("out of memory"),
28            SdlError::Others { msg } => f.write_str(msg),
29        }
30    }
31}
32
33impl std::error::Error for SdlError {}