kabu_types_entities/
pool_config.rs

1use crate::PoolClass;
2use std::collections::HashMap;
3use strum::IntoEnumIterator;
4
5#[derive(Clone)]
6pub struct PoolsLoadingConfig {
7    threads: Option<usize>,
8    is_enabled: HashMap<PoolClass, bool>,
9}
10
11impl PoolsLoadingConfig {
12    pub fn new() -> Self {
13        let mut is_enabled = HashMap::new();
14        for pool_class in PoolClass::iter() {
15            is_enabled.insert(pool_class, true);
16        }
17
18        Self { threads: None, is_enabled }
19    }
20
21    pub fn disable_all(self) -> Self {
22        let mut is_enabled = HashMap::new();
23        for pool_class in PoolClass::iter() {
24            is_enabled.insert(pool_class, false);
25        }
26
27        Self { is_enabled, ..self }
28    }
29
30    pub fn enable(self, pool_class: PoolClass) -> Self {
31        let mut is_enabled = self.is_enabled;
32        is_enabled.insert(pool_class, true);
33
34        Self { is_enabled, ..self }
35    }
36
37    pub fn disable(self, pool_class: PoolClass) -> Self {
38        let mut is_enabled = self.is_enabled;
39        is_enabled.insert(pool_class, true);
40
41        Self { is_enabled, ..self }
42    }
43
44    pub fn is_enabled(&self, pool_class: PoolClass) -> bool {
45        self.is_enabled.get(&pool_class).is_some_and(|s| *s)
46    }
47
48    pub fn with_threads(self, threads: usize) -> Self {
49        Self { threads: Some(threads), ..self }
50    }
51
52    pub fn threads(&self) -> Option<usize> {
53        self.threads
54    }
55}
56
57impl Default for PoolsLoadingConfig {
58    fn default() -> Self {
59        PoolsLoadingConfig::new()
60    }
61}