1use std::fmt;
2
3use cranelift_codegen::CodegenError as CraneliftError;
4use cranelift_codegen::settings::SetError;
5use cranelift_module::ModuleError;
6
7#[derive(Debug)]
9pub struct CodegenError(String);
10
11impl CodegenError {
12 pub(crate) fn new(message: impl Into<String>) -> Self {
13 Self(message.into())
14 }
15}
16
17impl fmt::Display for CodegenError {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 f.write_str(&self.0)
20 }
21}
22
23impl std::error::Error for CodegenError {}
24
25impl From<ModuleError> for CodegenError {
26 fn from(error: ModuleError) -> Self {
27 Self(error.to_string())
28 }
29}
30
31impl From<SetError> for CodegenError {
32 fn from(error: SetError) -> Self {
33 Self(error.to_string())
34 }
35}
36
37impl From<CraneliftError> for CodegenError {
38 fn from(error: CraneliftError) -> Self {
39 Self(error.to_string())
40 }
41}