interstice_core/persistence/
config.rs1use std::path::PathBuf;
6
7#[derive(Debug, Clone)]
9pub struct PersistenceConfig {
10 pub enabled: bool,
12 pub log_dir: PathBuf,
14 pub sync_on_append: bool,
16}
17
18impl PersistenceConfig {
19 pub fn default_safe() -> Self {
21 Self {
22 enabled: true,
23 log_dir: PathBuf::from("./interstice_logs"),
24 sync_on_append: true,
25 }
26 }
27
28 pub fn default_fast() -> Self {
30 Self {
31 enabled: true,
32 log_dir: PathBuf::from("./interstice_logs"),
33 sync_on_append: false,
34 }
35 }
36
37 pub fn disabled() -> Self {
39 Self {
40 enabled: false,
41 log_dir: PathBuf::from("./interstice_logs"),
42 sync_on_append: true,
43 }
44 }
45
46 pub fn with_log_dir(mut self, dir: PathBuf) -> Self {
48 self.log_dir = dir;
49 self
50 }
51
52 pub fn log_file_path(&self) -> PathBuf {
54 self.log_dir.join("transactions.log")
55 }
56}
57
58impl Default for PersistenceConfig {
59 fn default() -> Self {
60 Self::default_safe()
61 }
62}
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
69 fn test_default_config() {
70 let cfg = PersistenceConfig::default();
71 assert!(cfg.enabled);
72 assert!(cfg.sync_on_append);
73 }
74
75 #[test]
76 fn test_custom_config() {
77 let cfg = PersistenceConfig::disabled().with_log_dir(PathBuf::from("/tmp/logs"));
78 assert!(!cfg.enabled);
79 assert_eq!(cfg.log_dir, PathBuf::from("/tmp/logs"));
80 }
81
82 #[test]
83 fn test_log_file_path() {
84 let cfg = PersistenceConfig::default().with_log_dir(PathBuf::from("./data"));
85 assert_eq!(
86 cfg.log_file_path(),
87 PathBuf::from("./data/transactions.log")
88 );
89 }
90}