server_manager/config/
impl.rs

1use crate::*;
2
3impl ServerManagerConfig {
4    pub fn new(pid_file: String) -> Self {
5        Self {
6            pid_file,
7            ..Default::default()
8        }
9    }
10
11    pub fn set_pid_file(&mut self, pid_file: String) -> &mut Self {
12        self.pid_file = pid_file;
13        self
14    }
15
16    pub fn set_stop_hook<F, Fut>(&mut self, f: F) -> &mut Self
17    where
18        F: Fn() -> Fut + Send + Sync + 'static,
19        Fut: Future<Output = ()> + Send + 'static,
20    {
21        self.stop_hook = Arc::new(move || Box::pin(f()));
22        self
23    }
24
25    pub fn set_start_hook<F, Fut>(&mut self, f: F) -> &mut Self
26    where
27        F: Fn() -> Fut + Send + Sync + 'static,
28        Fut: Future<Output = ()> + Send + 'static,
29    {
30        self.start_hook = Arc::new(move || Box::pin(f()));
31        self
32    }
33
34    pub fn get_pid_file(&self) -> &str {
35        &self.pid_file
36    }
37
38    pub fn get_stop_hook(&self) -> &Hook {
39        &self.stop_hook
40    }
41
42    pub fn get_start_hook(&self) -> &Hook {
43        &self.start_hook
44    }
45}
46
47impl Default for ServerManagerConfig {
48    fn default() -> Self {
49        let empty_hook: Hook = Arc::new(|| Box::pin(async {}));
50        Self {
51            pid_file: Default::default(),
52            stop_hook: empty_hook.clone(),
53            start_hook: empty_hook,
54        }
55    }
56}