From a76cd56b9f8cce132555f6c3b59d76da5ae86f6b Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 30 Mar 2021 16:51:51 +0530 Subject: add new catch-all error types --- src/error.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/error.rs (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..ff25db7 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,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 {} -- cgit v1.2.3