Skip to main content

msg_socket/connection/
state.rs

1/// Abstraction to represent the state of a connection.
2///
3/// * `C` is the channel type, which is used to send and receive generic messages.
4/// * `B` is the backoff type, used to control the backoff state for inactive connections.
5/// * `A` is the address type, used to represent the address of the connection.
6pub enum ConnectionState<C, B, A> {
7    Active {
8        /// Channel to control the underlying connection. This is used to send
9        /// and receive any kind of message in any direction.
10        channel: C,
11    },
12    Inactive {
13        addr: A,
14        /// The current backoff state for inactive connections.
15        backoff: B,
16    },
17}
18
19impl<C, B, A> ConnectionState<C, B, A> {
20    /// Returns `true` if the connection is active.
21    pub fn is_active(&self) -> bool {
22        matches!(self, Self::Active { .. })
23    }
24
25    /// Returns `true` if the connection is inactive.
26    pub fn is_inactive(&self) -> bool {
27        matches!(self, Self::Inactive { .. })
28    }
29}