#[cfg(test)]
mod tcp_type_test;
use std::fmt;
#[derive(Default, PartialEq, Eq, Debug, Copy, Clone)]
pub enum TcpType {
#[default]
Unspecified,
Active,
Passive,
SimultaneousOpen,
}
impl From<&str> for TcpType {
fn from(raw: &str) -> Self {
match raw {
"active" => Self::Active,
"passive" => Self::Passive,
"so" => Self::SimultaneousOpen,
_ => Self::Unspecified,
}
}
}
impl fmt::Display for TcpType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match *self {
Self::Active => "active",
Self::Passive => "passive",
Self::SimultaneousOpen => "so",
Self::Unspecified => "unspecified",
};
write!(f, "{s}")
}
}