use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum SyslogErrCode
{
InternalError,
#[cfg(feature = "use_sync_queue")]
SyslogThreadNotAvailable,
#[cfg(feature = "use_sync_queue")]
UnboundedChannelError,
}
pub struct SyslogError
{
errcode: SyslogErrCode,
message: String,
}
impl SyslogError
{
pub fn new(errcode: SyslogErrCode, msg: String) -> Self
{
return SyslogError{errcode: errcode, message: msg};
}
pub fn get_errcode(&self) -> SyslogErrCode
{
return self.errcode;
}
pub fn eject_string(self) -> String
{
return self.message;
}
}
impl fmt::Display for SyslogError
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
{
write!(f, "{}", self.message)
}
}
impl fmt::Debug for SyslogError
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
{
write!(f, "{}", self.message)
}
}
pub type SyRes<T> = Result<T, SyslogError>;
#[macro_export]
macro_rules! throw_error
{
($($arg:tt)*) => (
return std::result::Result::Err(SyslogError::new(SyslogErrCode::InternalError, format!($($arg)*)))
)
}
#[macro_export]
macro_rules! map_error
{
($($arg:tt)*) => (
return SyslogError::new(SyslogErrCode::InternalError, format!($($arg)*))
)
}
#[macro_export]
macro_rules! throw_error_code
{
($code:expr, $($arg:tt)*) => (
return std::result::Result::Err(SyslogError::new($code, format!($($arg)*)))
)
}
#[macro_export]
macro_rules! map_error_code
{
($code:expr, $($arg:tt)*) => (
return SyslogError::new($code, format!($($arg)*))
)
}