qubit_dcl/double_checked/
executor_builder.rs1use std::marker::PhantomData;
14
15use super::{
16 ExecutionLogger,
17 executor_lock_builder::ExecutorLockBuilder,
18};
19use crate::lock::Lock;
20
21#[derive(Debug, Default, Clone)]
26pub struct ExecutorBuilder {
27 logger: ExecutionLogger,
29
30 catch_panics: bool,
32}
33
34impl ExecutorBuilder {
35 #[inline]
37 pub fn log_unmet_condition(mut self, level: log::Level, message: impl Into<String>) -> Self {
38 self.logger.set_unmet_condition(Some(level), message);
39 self
40 }
41
42 #[inline]
44 pub fn disable_unmet_condition_logging(mut self) -> Self {
45 self.logger.disable_unmet_condition();
46 self
47 }
48
49 #[inline]
51 pub fn log_prepare_failure(
52 mut self,
53 level: log::Level,
54 message_prefix: impl Into<String>,
55 ) -> Self {
56 self.logger.set_prepare_failure(Some(level), message_prefix);
57 self
58 }
59
60 #[inline]
62 pub fn disable_prepare_failure_logging(mut self) -> Self {
63 self.logger.disable_prepare_failure();
64 self
65 }
66
67 #[inline]
69 pub fn log_prepare_commit_failure(
70 mut self,
71 level: log::Level,
72 message_prefix: impl Into<String>,
73 ) -> Self {
74 self.logger
75 .set_prepare_commit_failure(Some(level), message_prefix);
76 self
77 }
78
79 #[inline]
81 pub fn disable_prepare_commit_failure_logging(mut self) -> Self {
82 self.logger.disable_prepare_commit_failure();
83 self
84 }
85
86 #[inline]
88 pub fn log_prepare_rollback_failure(
89 mut self,
90 level: log::Level,
91 message_prefix: impl Into<String>,
92 ) -> Self {
93 self.logger
94 .set_prepare_rollback_failure(Some(level), message_prefix);
95 self
96 }
97
98 #[inline]
100 pub fn disable_prepare_rollback_failure_logging(mut self) -> Self {
101 self.logger.disable_prepare_rollback_failure();
102 self
103 }
104
105 #[inline]
116 pub fn on<L, T>(self, lock: L) -> ExecutorLockBuilder<L, T>
117 where
118 L: Lock<T>,
119 {
120 ExecutorLockBuilder {
121 lock,
122 logger: self.logger,
123 catch_panics: self.catch_panics,
124 _phantom: PhantomData,
125 }
126 }
127
128 #[inline]
130 pub fn catch_panics(mut self) -> Self {
131 self.catch_panics = true;
132 self
133 }
134
135 #[inline]
138 pub fn set_catch_panics(mut self, catch_panics: bool) -> Self {
139 self.catch_panics = catch_panics;
140 self
141 }
142
143 #[inline]
145 pub fn disable_catch_panics(mut self) -> Self {
146 self.catch_panics = false;
147 self
148 }
149}