Skip to main content

sql_middleware/pool/
options.rs

1/// Shared options for `bb8`-backed middleware pools.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub struct MiddlewarePoolOptions {
4    /// Whether `bb8` should call the backend's validation hook before checkout.
5    pub test_on_check_out: bool,
6}
7
8impl Default for MiddlewarePoolOptions {
9    fn default() -> Self {
10        Self {
11            test_on_check_out: true,
12        }
13    }
14}
15
16impl MiddlewarePoolOptions {
17    #[must_use]
18    pub fn new() -> Self {
19        Self::default()
20    }
21
22    #[must_use]
23    pub fn with_test_on_check_out(mut self, test_on_check_out: bool) -> Self {
24        self.test_on_check_out = test_on_check_out;
25        self
26    }
27
28    pub(crate) fn apply_to<M>(self, builder: bb8::Builder<M>) -> bb8::Builder<M>
29    where
30        M: bb8::ManageConnection,
31    {
32        builder.test_on_check_out(self.test_on_check_out)
33    }
34}