graphics_error/display/
mod.rs

1use crate::{GraphicsError, GraphicsErrorKind};
2use std::{
3    error::Error,
4    fmt::{Display, Formatter},
5};
6
7impl Display for GraphicsError {
8    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
9        match &self.kind {
10            GraphicsErrorKind::ParseError(e) => {
11                writeln!(f, "Parse Error at: {}, {}", self.line, self.column)?;
12                writeln!(f, "{:indent$}{msg}", " ", indent = 4, msg = e)
13            }
14            GraphicsErrorKind::IOError(e) => {
15                match &self.file {
16                    None => writeln!(f, "IO Error at: {}, {}", self.line, self.column)?,
17                    Some(file) => writeln!(f, "IO Error at: {}, {} in {:?}", self.line, self.column, file)?,
18                };
19                writeln!(f, "{:indent$}{msg}", " ", indent = 4, msg = e)
20            }
21        }
22    }
23}
24
25impl Error for GraphicsError {}