aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
blob: ff25db71889ed8f2a0bbceea3262669b32f14147 (plain)
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 crate::lisp::error::LispError;

use std::{error, fmt, io};

use sdl2::ttf;

#[derive(Debug)]
pub enum AppError {
    Lisp(LispError),
    File(io::Error),
    Sdl(String),
    SdlTTF(SdlTTFError),
}

impl fmt::Display for AppError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Lisp(e) => write!(f, "lisp error: {}", e),
            Self::File(e) => write!(f, "file error: {}", e),
            Self::Sdl(e) => write!(f, "sdl2 error: {}", e),
            Self::SdlTTF(e) => write!(f, "ttf error: {}", e),
        }
    }
}

#[derive(Debug)]
pub enum SdlTTFError {
    Font(ttf::FontError),
    Init(ttf::InitError),
}

impl fmt::Display for SdlTTFError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Font(e) => write!(f, "font error: {}", e),
            Self::Init(e) => write!(f, "init error: {}", e),
        }
    }
}

impl error::Error for AppError {}
impl error::Error for SdlTTFError {}