protoflow_core/
port_state.rs

1// This is free and unencumbered software released into the public domain.
2
3#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
6pub enum PortState {
7    #[default]
8    Closed,
9    Open,
10    Connected,
11}
12
13impl PortState {
14    /// Checks whether the port state is currently closed.
15    pub fn is_closed(&self) -> bool {
16        *self == PortState::Closed
17    }
18
19    /// Checks whether the port state is currently open.
20    pub fn is_open(&self) -> bool {
21        *self == PortState::Open
22    }
23
24    /// Checks whether the port state is currently connected.
25    pub fn is_connected(&self) -> bool {
26        *self == PortState::Connected
27    }
28
29    pub fn to_str(&self) -> &str {
30        use PortState::*;
31        match self {
32            Closed => "closed",
33            Open => "open",
34            Connected => "connected",
35        }
36    }
37}
38
39impl AsRef<str> for PortState {
40    fn as_ref(&self) -> &str {
41        self.to_str()
42    }
43}