cranelift_codegen_meta/
error.rs1use std::fmt;
3use std::io;
4
5#[derive(Debug)]
8pub struct Error {
9 inner: Box<ErrorInner>,
10}
11
12impl Error {
13 pub fn with_msg<S: Into<String>>(msg: S) -> Error {
15 Error {
16 inner: Box::new(ErrorInner::Msg(msg.into())),
17 }
18 }
19}
20
21impl std::error::Error for Error {}
22
23impl fmt::Display for Error {
24 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25 write!(f, "{}", self.inner)
26 }
27}
28
29impl From<io::Error> for Error {
30 fn from(e: io::Error) -> Self {
31 Error {
32 inner: Box::new(ErrorInner::IoError(e)),
33 }
34 }
35}
36
37#[derive(Debug)]
38enum ErrorInner {
39 Msg(String),
40 IoError(io::Error),
41}
42
43impl fmt::Display for ErrorInner {
44 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45 match *self {
46 ErrorInner::Msg(ref s) => write!(f, "{s}"),
47 ErrorInner::IoError(ref e) => write!(f, "{e}"),
48 }
49 }
50}