protoflow_core/
port_state.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// This is free and unencumbered software released into the public domain.

#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum PortState {
    #[default]
    Closed,
    Open,
    Connected,
}

impl PortState {
    /// Checks whether the port state is currently closed.
    pub fn is_closed(&self) -> bool {
        *self == PortState::Closed
    }

    /// Checks whether the port state is currently open.
    pub fn is_open(&self) -> bool {
        *self == PortState::Open
    }

    /// Checks whether the port state is currently connected.
    pub fn is_connected(&self) -> bool {
        *self == PortState::Connected
    }

    pub fn to_str(&self) -> &str {
        use PortState::*;
        match self {
            Closed => "closed",
            Open => "open",
            Connected => "connected",
        }
    }
}

impl AsRef<str> for PortState {
    fn as_ref(&self) -> &str {
        self.to_str()
    }
}