1use core::fmt;
2use std::io;
3
4pub type Result<T> = core::result::Result<T, Error>;
5
6#[derive(Debug)]
7pub enum Error {
8 Custom(String),
9
10 MeshGeneration(String),
12
13 Deformation(String),
15
16 FileSystem(io::Error),
18}
19
20impl fmt::Display for Error {
21 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22 match self {
23 Error::Custom(msg) => write!(f, "🔴 Error: {msg}"),
24 Error::MeshGeneration(msg) => write!(f, "🔴 Mesh generation error: {msg}"),
25 Error::Deformation(msg) => write!(f, "🔴 Deformation error: {msg}"),
26 Error::FileSystem(err) => write!(f, "🔴 IO error: {err}"),
27 }
28 }
29}
30
31impl std::error::Error for Error {
33 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
35 match self {
36 Error::Custom(_) => None,
38 Error::MeshGeneration(_) => None,
39 Error::Deformation(_) => None,
40 Error::FileSystem(err) => Some(err),
41 }
42 }
43}
44
45impl From<&str> for Error {
46 fn from(value: &str) -> Self {
47 Self::Custom(value.to_string())
48 }
49}
50
51impl From<String> for Error {
52 fn from(value: String) -> Self {
53 Self::Custom(value)
54 }
55}
56
57impl From<io::Error> for Error {
58 fn from(err: io::Error) -> Self {
59 Self::FileSystem(err)
60 }
61}