mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-08 19:44:57 -05:00
chore(rust): impl std::error::Error for CompilerError
All types which are errors should impl the std::error::Error trait. So that for example they could be put inside a `Box<dyn std::error::Error>`.
This commit is contained in:
@@ -4,10 +4,27 @@ use crate::mlir::ffi;
|
||||
use std::os::raw::c_char;
|
||||
use std::{ffi::CStr, path::Path};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CompilerError(String);
|
||||
|
||||
/// Retreive buffer of the error message from a C struct.
|
||||
// Manual implementation to use pretty formatting of line-breaks
|
||||
// contained in the String.
|
||||
impl std::fmt::Debug for CompilerError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
writeln!(f, "CompilerError {{")?;
|
||||
writeln!(f, "{:#}", self.0)?;
|
||||
writeln!(f, "}}")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CompilerError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
<Self as std::fmt::Debug>::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for CompilerError {}
|
||||
|
||||
/// Retrieve buffer of the error message from a C struct.
|
||||
trait CStructErrorMsg {
|
||||
fn error_msg(&self) -> *const i8;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user