agner_sup/common/
init_type.rs1use std::time::Duration;
2
3const DEFAULT_INIT_TIMEOUT: Duration = Duration::from_secs(5);
4const DEFAULT_STOP_TIMEOUT: Duration = Duration::from_secs(5);
5
6#[derive(Debug, Clone, Copy)]
7pub enum InitType {
8 NoAck,
9 WithAck(WithAck),
10}
11
12#[derive(Debug, Clone, Copy)]
13pub struct WithAck {
14 pub init_timeout: Duration,
15 pub stop_timeout: Duration,
16}
17
18impl InitType {
19 pub fn no_ack() -> Self {
20 Self::NoAck
21 }
22 pub fn with_ack() -> Self {
23 Self::WithAck(Default::default())
24 }
25}
26
27impl WithAck {
28 pub fn new() -> Self {
29 Default::default()
30 }
31 pub fn with_init_timeout(self, init_timeout: Duration) -> Self {
32 Self { init_timeout, ..self }
33 }
34 pub fn with_stop_timeout(self, stop_timeout: Duration) -> Self {
35 Self { stop_timeout, ..self }
36 }
37}
38
39impl Default for WithAck {
40 fn default() -> Self {
41 Self { init_timeout: DEFAULT_INIT_TIMEOUT, stop_timeout: DEFAULT_STOP_TIMEOUT }
42 }
43}
44
45impl From<WithAck> for InitType {
46 fn from(with_ack: WithAck) -> Self {
47 Self::WithAck(with_ack)
48 }
49}