1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Imports
use std::{
    error::Error,
    fmt::{
        Display,
        Formatter,
        Result
    }
};


/// Graphics processing specific error type.
#[derive(Debug)]
pub struct GraphicsError {
    msg: String
}
impl GraphicsError {
    /// New error with message.
    pub(crate) fn new(msg: &str) -> Self {
        Self {
            msg: msg.to_owned()
        }
    }
}
impl Display for GraphicsError {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(f, "{}", self.msg)
    }
}
impl Error for GraphicsError {}


// Tests
#[cfg(test)]
mod tests {
    use super::GraphicsError;

    #[test]
    fn graphics_error() {
        assert_eq!(GraphicsError::new("Not enough!").to_string(), "Not enough!");
    }
}