use crate::{ import::*, ActorInfo, DynError };
pub type ThesRes<T> = Result<T, ThesErr>;
#[ derive( Debug ) ]
pub enum ThesErr
{
ActorStoppedBeforeResponse
{
info: Arc<ActorInfo>,
},
MailboxClosed
{
info: Arc<ActorInfo>,
src : Option<DynError>,
},
Spawn
{
info: Arc<ActorInfo>,
src : SpawnError,
}
}
impl ThesErr
{
pub fn actor_info( &self ) -> &ActorInfo
{
match self
{
Self::ActorStoppedBeforeResponse { info, .. } => info,
Self::MailboxClosed { info, .. } => info,
Self::Spawn { info, .. } => info,
}
}
}
impl Error for ThesErr
{
fn source( &self ) -> Option< &(dyn Error + 'static) >
{
match &self
{
Self::ActorStoppedBeforeResponse { .. } => None ,
Self::MailboxClosed { src, .. } => src.as_ref().map(|e| {let a: &(dyn Error + 'static) = e.as_ref(); a} ) ,
Self::Spawn { src, .. } => Some(src) ,
}
}
}
impl fmt::Display for ThesErr
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
{
match &self
{
ThesErr::ActorStoppedBeforeResponse{ info, .. } =>
write!( f, "The mailbox was closed before the result of the computation got returned upon `call`. For actor: {}", info ),
ThesErr::MailboxClosed{ info, .. } =>
write!( f, "You try to use a mailbox that is already closed. For actor: {}", info ),
ThesErr::Spawn{ info, .. } =>
write!( f, "Failed to spawn the mailbox for actor: {}", info ),
}
}
}
impl PartialEq for ThesErr
{
fn eq( &self, other: &Self ) -> bool
{
std::mem::discriminant( self ) == std::mem::discriminant( other )
&& self.actor_info() == other.actor_info()
}
}
impl Eq for ThesErr {}