rustemo_compiler/
error.rs1use std::fmt::Display;
2
3pub type Result<R> = std::result::Result<R, Error>;
4
5#[derive(Debug)]
6pub enum Error {
7 RustemoError(rustemo::Error),
8 IOError(std::io::Error),
9 SynError(syn::Error),
10 Error(String),
11}
12
13impl Error {
14 pub fn to_locfile_str(&self) -> String {
17 match self {
18 Error::RustemoError(e) => e.to_locfile_str(),
19 Error::SynError(e) => format!("Syn error: {e}"),
20 Error::IOError(e) => format!("IOError: {e}"),
21 Error::Error(e) => format!("Error: {e}"),
22 }
23 }
24}
25
26impl Display for Error {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 match self {
29 Error::RustemoError(e) => write!(f, "{e}"),
30 Error::SynError(e) => write!(f, "Syn error: {e}"),
31 Error::IOError(e) => write!(f, "IOError: {e}"),
32 Error::Error(e) => write!(f, "Error: {e}"),
33 }
34 }
35}
36
37impl From<rustemo::Error> for Error {
38 fn from(e: rustemo::Error) -> Self {
39 Error::RustemoError(e)
40 }
41}
42
43impl From<std::io::Error> for Error {
44 fn from(e: std::io::Error) -> Self {
45 Error::IOError(e)
46 }
47}
48
49impl From<syn::Error> for Error {
50 fn from(e: syn::Error) -> Self {
51 Error::SynError(e)
52 }
53}