(
hook: impl Fn(&T, &mut crate::fmt::HookContext<T>) + Send + Sync + 'static,
)
| 195 | /// [`Error::provide`]: std::error::Error::provide |
| 196 | #[cfg(any(feature = "std", feature = "hooks"))] |
| 197 | pub fn install_debug_hook<T: Send + Sync + 'static>( |
| 198 | hook: impl Fn(&T, &mut crate::fmt::HookContext<T>) + Send + Sync + 'static, |
| 199 | ) { |
| 200 | install_builtin_hooks(); |
| 201 | |
| 202 | // TODO: Use `let ... else` when MSRV is 1.65 |
| 203 | #[cfg(feature = "std")] |
| 204 | let mut lock = FMT_HOOK.write().unwrap_or_else(|_| { |
| 205 | unreachable!( |
| 206 | "Hook is poisoned. This is considered a bug and should be reported to \ |
| 207 | https://github.com/hashintel/hash/issues/new/choose" |
| 208 | ) |
| 209 | }); |
| 210 | |
| 211 | // The spin RwLock cannot panic |
| 212 | #[cfg(all(not(feature = "std"), feature = "hooks"))] |
| 213 | let mut lock = FMT_HOOK.write(); |
| 214 | |
| 215 | lock.insert(hook); |
| 216 | } |
| 217 | |
| 218 | /// Returns the hook that was previously set by [`install_debug_hook`]. |
| 219 | /// |
nothing calls this directly
no test coverage detected