try_drop/handlers/
fns.rs

1use super::{fallback, primary};
2use std::boxed::Box;
3
4#[cfg(feature = "global")]
5use crate::{GlobalDynFallibleTryDropStrategy, GlobalTryDropStrategy};
6
7#[cfg(feature = "thread-local")]
8use crate::{ThreadLocalFallibleTryDropStrategy, ThreadLocalTryDropStrategy};
9
10/// This installs the primary and fallback global handlers.
11#[cfg(feature = "global")]
12pub fn install_global_handlers(
13    primary: impl GlobalDynFallibleTryDropStrategy,
14    fallback: impl GlobalTryDropStrategy,
15) {
16    install_global_handlers_dyn(Box::new(primary), Box::new(fallback))
17}
18
19/// This installs the primary and fallback global handlers. Must be a dynamic trait object.
20#[cfg(feature = "global")]
21pub fn install_global_handlers_dyn(
22    primary: Box<dyn GlobalDynFallibleTryDropStrategy>,
23    fallback: Box<dyn GlobalTryDropStrategy>,
24) {
25    primary::global::install_dyn(primary);
26    fallback::global::install_dyn(fallback);
27}
28
29/// This uninstalls the primary and fallback global handlers.
30#[cfg(feature = "global")]
31pub fn uninstall_globally() {
32    primary::global::uninstall();
33    fallback::global::uninstall();
34}
35
36/// This installs the primary and fallback thread local handlers.
37#[cfg(feature = "thread-local")]
38pub fn install_thread_local_handlers(
39    primary: impl ThreadLocalFallibleTryDropStrategy,
40    fallback: impl ThreadLocalTryDropStrategy,
41) {
42    install_thread_local_handlers_dyn(Box::new(primary), Box::new(fallback))
43}
44
45/// This installs the primary and fallback thread local handlers. Must be a dynamic trait
46/// object.
47#[cfg(feature = "thread-local")]
48pub fn install_thread_local_handlers_dyn(
49    primary: Box<dyn ThreadLocalFallibleTryDropStrategy>,
50    fallback: Box<dyn ThreadLocalTryDropStrategy>,
51) {
52    primary::thread_local::install_dyn(primary);
53    fallback::thread_local::install_dyn(fallback);
54}
55
56/// This installs the primary and fallback thread local handlers for this scope.
57#[cfg(feature = "thread-local")]
58pub fn install_thread_local_handlers_for_this_scope(
59    primary: impl ThreadLocalFallibleTryDropStrategy,
60    fallback: impl ThreadLocalTryDropStrategy,
61) -> (
62    primary::thread_local::ScopeGuard,
63    fallback::thread_local::ScopeGuard,
64) {
65    install_thread_local_handlers_for_this_scope_dyn(Box::new(primary), Box::new(fallback))
66}
67
68/// This installs the primary and fallback thread local handlers for this scope. Must be a
69/// dynamic trait object.
70#[cfg(feature = "thread-local")]
71pub fn install_thread_local_handlers_for_this_scope_dyn(
72    primary: Box<dyn ThreadLocalFallibleTryDropStrategy>,
73    fallback: Box<dyn ThreadLocalTryDropStrategy>,
74) -> (
75    primary::thread_local::ScopeGuard,
76    fallback::thread_local::ScopeGuard,
77) {
78    (
79        primary::thread_local::scope_dyn(primary),
80        fallback::thread_local::scope_dyn(fallback),
81    )
82}
83
84/// This uninstalls the primary and fallback thread local handlers.
85#[cfg(feature = "thread-local")]
86pub fn uninstall_for_thread() {
87    primary::thread_local::uninstall();
88    fallback::thread_local::uninstall();
89}