Path: blob/main/cranelift/srcgen/src/error.rs
1692 views
//! Defines an `Error` returned during source code generation.12use std::fmt;3use std::io;45/// An error that occurred when the cranelift_codegen_meta crate was generating6/// source files for the cranelift_codegen crate.7#[derive(Debug)]8pub struct Error {9inner: Box<ErrorInner>,10}1112impl Error {13/// Create a new error object with the given message.14pub fn with_msg<S: Into<String>>(msg: S) -> Error {15Error {16inner: Box::new(ErrorInner::Msg(msg.into())),17}18}19}2021impl std::error::Error for Error {}2223impl fmt::Display for Error {24fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {25write!(f, "{}", self.inner)26}27}2829impl From<io::Error> for Error {30fn from(e: io::Error) -> Self {31Error {32inner: Box::new(ErrorInner::IoError(e)),33}34}35}3637#[derive(Debug)]38enum ErrorInner {39Msg(String),40IoError(io::Error),41}4243impl fmt::Display for ErrorInner {44fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {45match *self {46ErrorInner::Msg(ref s) => write!(f, "{s}"),47ErrorInner::IoError(ref e) => write!(f, "{e}"),48}49}50}515253