diff --git a/src/eyreish/mod.rs b/src/eyreish/mod.rs index 386daba..b9b15b1 100644 --- a/src/eyreish/mod.rs +++ b/src/eyreish/mod.rs @@ -54,8 +54,7 @@ pub struct Report { } /// -pub type ErrorHook = - Box Box + Sync + Send + 'static>; +pub type ErrorHook = Box Box + Sync + Send>; static HOOK: OnceCell = OnceCell::new(); @@ -80,10 +79,19 @@ pub fn set_hook(hook: ErrorHook) -> Result<(), InstallError> { HOOK.set(hook).map_err(|_| InstallError) } +/** +Get the error hook. + +If the error hook has not been set, it is set to its default value. +*/ +pub fn get_hook() -> &'static ErrorHook { + HOOK.get_or_init(|| Box::new(get_default_printer)) +} + #[cfg_attr(track_caller, track_caller)] #[cfg_attr(not(track_caller), allow(unused_mut))] fn capture_handler(error: &(dyn Diagnostic + 'static)) -> Box { - let hook = HOOK.get_or_init(|| Box::new(get_default_printer)).as_ref(); + let hook = get_hook().as_ref(); #[cfg(track_caller)] { @@ -97,7 +105,7 @@ fn capture_handler(error: &(dyn Diagnostic + 'static)) -> Box } } -fn get_default_printer(_err: &(dyn Diagnostic + 'static)) -> Box { +fn get_default_printer(_err: &dyn Diagnostic) -> Box { #[cfg(feature = "fancy")] return Box::new(MietteHandler::new()); #[cfg(not(feature = "fancy"))]