Skip to main content

noxu_db/
stats_config.rs

1//! Configuration for statistics retrieval operations.
2//!
3//! Implements `StatsConfig`.
4
5/// Specifies the attributes of a statistics retrieval operation.
6///
7/// Pass to [`Environment::get_stats`][crate::environment::Environment::get_stats] or
8/// [`Database::get_stats`][crate::database::Database::get_stats].
9///
10/// # Defaults
11///
12/// - `fast = false` — collect all statistics, including those that require an
13///   expensive action such as a tree traversal or lock-table scan.
14/// - `clear = false` — do not reset counters after reading them.
15#[derive(Clone, Debug, Default)]
16pub struct StatsConfig {
17    /// If `true`, return only values that do not require expensive actions
18    /// (e.g. skip B-tree traversal counts).  Implements `StatsConfig.setFast(true)`.
19    pub fast: bool,
20    /// If `true`, reset all counters to zero after reading them.
21    /// Implements `StatsConfig.setClear(true)`.
22    pub clear: bool,
23}
24
25impl StatsConfig {
26    /// Creates a `StatsConfig` with all default settings.
27    pub fn new() -> Self {
28        Self::default()
29    }
30
31    /// Convenience constructor: `fast = false`, `clear = true`.
32    ///
33    /// Implements `StatsConfig.CLEAR` constant.
34    pub fn clear() -> Self {
35        Self { fast: false, clear: true }
36    }
37
38    /// Builder: set `fast`.
39    pub fn with_fast(mut self, fast: bool) -> Self {
40        self.fast = fast;
41        self
42    }
43
44    /// Builder: set `clear`.
45    pub fn with_clear(mut self, clear: bool) -> Self {
46        self.clear = clear;
47        self
48    }
49
50    /// Sets `fast` and returns `&mut self` for chaining.
51    pub fn set_fast(&mut self, fast: bool) -> &mut Self {
52        self.fast = fast;
53        self
54    }
55
56    /// Sets `clear` and returns `&mut self` for chaining.
57    pub fn set_clear(&mut self, clear: bool) -> &mut Self {
58        self.clear = clear;
59        self
60    }
61}