smlm_hawk_core/config/
mod.rs1pub use self::algorithm_config::{AlgorithmConfig};
2pub use self::memory::{Memory};
3pub use self::negative_handling::{NegativeHandling};
4pub use self::output_style::{OutputStyle};
5pub use self::run_style::{RunStyle};
6pub use self::threading::{Threading};
7pub use self::validation::{Validation};
8
9mod algorithm_config;
10mod memory;
11mod negative_handling;
12mod output_style;
13mod run_style;
14mod threading;
15mod validation;
16
17use crate::concurrency::{CancellationToken};
18
19#[cfg(feature = "json")]
20use crate::io::{Config as IoConfig};
21#[cfg(feature = "json")]
22use std::fmt::{Display, Formatter};
23
24#[derive(Debug, Default)]
25pub struct Config
26{
27 threading: Threading,
28 memory: Memory,
29 run_style: RunStyle,
30 algorithm: AlgorithmConfig,
31 validation: Option<Validation>,
32 cancellation_token: CancellationToken
33}
34
35impl Config
36{
37 pub fn new(threading: Threading,
38 memory: Memory,
39 run_style: RunStyle,
40 algorithm_config: AlgorithmConfig,
41 validation: Option<Validation>) -> Self
42 {
43 Self
44 {
45 threading,
46 memory,
47 run_style,
48 algorithm: algorithm_config,
49 validation,
50 cancellation_token: CancellationToken::new()
51 }
52 }
53
54 pub fn cancellation_token(&self) -> CancellationToken
55 {
56 self.cancellation_token.clone()
57 }
58
59 pub fn cancel(&mut self) -> ()
60 {
61 self.cancellation_token.cancel()
62 }
63
64 pub fn threading(&self) -> &Threading
65 {
66 &self.threading
67 }
68
69 pub fn memory(&self) -> &Memory
70 {
71 &self.memory
72 }
73
74 pub fn is_fragmented(&self) -> bool
75 {
76 self.memory.fragment()
77 }
78
79 pub fn run_style(&self) -> &RunStyle
80 {
81 &self.run_style
82 }
83
84 pub fn algorithm_config(&self) -> &AlgorithmConfig
85 {
86 &self.algorithm
87 }
88
89 pub fn validation(&self) -> Option<&Validation>
90 {
91 self.validation.as_ref()
92 }
93
94 #[cfg(feature = "json")]
95 pub fn to_io(&self) -> IoConfig
96 {
97 IoConfig::from(self)
98 }
99}
100
101impl AsRef<AlgorithmConfig> for Config
102{
103 fn as_ref(&self) -> &AlgorithmConfig
104 {
105 &self.algorithm
106 }
107}
108
109#[cfg(feature = "json")]
110impl Display for Config
111{
112 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error>
113 {
114 write!(f, "{}", self.to_io())
115 }
116}
117
118#[cfg(test)]
119mod tests
120{
121 use super::*;
122
123 #[test]
124 fn default_config()
125 {
126 let config = Config::default();
127 assert_eq!(config.threading(), &Threading::default());
128 assert_eq!(config.memory(), &Memory::default());
129 assert_eq!(config.run_style(), &RunStyle::default());
130 assert_eq!(config.algorithm_config(), &AlgorithmConfig::default());
131 assert_eq!(config.validation(), None)
132 }
133}