use std::fmt;
#[derive(Debug)]
pub struct PirError(pub String);
impl fmt::Display for PirError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::error::Error for PirError {}
impl PirError {
pub fn new(msg: impl Into<String>) -> Self {
Self(msg.into())
}
}
impl From<std::io::Error> for PirError {
fn from(err: std::io::Error) -> Self {
Self(err.to_string())
}
}
impl From<bincode::Error> for PirError {
fn from(err: bincode::Error) -> Self {
Self(err.to_string())
}
}
pub type Result<T> = std::result::Result<T, PirError>;
macro_rules! pir_err {
($($arg:tt)*) => {
$crate::pir::error::PirError(format!($($arg)*))
};
}
pub(crate) use pir_err;