use std::{
any::{self},
cmp, error, fmt,
hash::{Hash, Hasher},
sync::{
Arc, Mutex,
atomic::{AtomicPtr, Ordering},
},
};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize, ser::SerializeStruct};
use tokio::{
sync::{mpsc, oneshot},
time::error::Elapsed,
};
use crate::{Actor, actor::ActorId, mailbox::Signal, reply::ReplyError};
type ErrorHookFn = fn(&PanicError);
static PANIC_HOOK: AtomicPtr<()> = AtomicPtr::new(default_panic_hook as *mut ());
#[allow(unused_variables)]
fn default_panic_hook(err: &PanicError) {
#[cfg(feature = "tracing")]
tracing::error!("actor panicked: {err:?}");
}
pub fn set_actor_error_hook(hook: ErrorHookFn) {
let fn_ptr = hook as *mut ();
PANIC_HOOK.store(fn_ptr, Ordering::SeqCst);
}
pub(crate) fn invoke_actor_error_hook(err: &PanicError) {
let fn_ptr = PANIC_HOOK.load(Ordering::SeqCst);
let hook = unsafe { std::mem::transmute::<*mut (), ErrorHookFn>(fn_ptr) };
hook(err);
}
include!("error/send.rs");
include!("error/panic.rs");
include!("error/infallible.rs");
include!("error/registry.rs");
include!("error/remote.rs");