pub( crate ) mod private
{
pub use std::error::Error as ErrorInterface;
#[ macro_export ]
macro_rules! err
{
( $msg : expr ) =>
{
$crate::BasicError::new( $msg ).into()
};
( $msg : expr, $( $arg : expr ),+ $(,)? ) =>
{
$crate::BasicError::new( format!( $msg, $( $arg ),+ ) ).into()
};
}
#[ macro_export ]
macro_rules! return_err
{
( $msg : expr ) =>
{
return Result::Err( $crate::err!( $msg ) )
};
( $msg : expr, $( $arg : expr ),+ $(,)? ) =>
{
return Result::Err( $crate::err!( $msg, $( $arg ),+ ) )
};
}
#[ derive( core::fmt::Debug, core::clone::Clone, core::cmp::PartialEq, core::cmp::Eq ) ]
pub struct BasicError
{
msg : String,
}
impl BasicError
{
pub fn new< Msg : Into< String > >( msg : Msg ) -> BasicError
{
BasicError { msg : msg.into() }
}
pub fn msg( &self ) -> &String
{
&self.msg
}
}
impl core::fmt::Display for BasicError
{
fn fmt(&self, f: &mut core::fmt::Formatter< '_ >) -> core::fmt::Result
{
write!( f, "{}", self.msg )
}
}
impl ErrorInterface for BasicError
{
fn description( &self ) -> &str
{
&self.msg
}
}
impl< T > From< BasicError > for Result< T, BasicError >
{
#[ inline( always ) ]
fn from( src : BasicError ) -> Self
{
Result::Err( src )
}
}
pub use err;
pub use return_err;
}
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use protected::*;
pub mod protected
{
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::orphan::*;
}
pub mod orphan
{
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::exposed::*;
}
pub mod exposed
{
#[ doc( inline ) ]
#[ allow( unused_imports ) ]
pub use super::prelude::*;
}
pub mod prelude
{
pub use super::private::err;
pub use super::private::return_err;
pub use super::private::ErrorInterface;
pub use super::private::BasicError;
}