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
use std::{
error::Error,
fmt::{
Display,
Formatter,
Result
}
};
#[derive(Debug)]
pub struct GraphicsError {
msg: String
}
impl GraphicsError {
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 {}
#[cfg(test)]
mod tests {
use super::GraphicsError;
#[test]
fn graphics_error() {
assert_eq!(GraphicsError::new("Not enough!").to_string(), "Not enough!");
}
}