ufwctl 0.1.0

Linux-only Rust library for managing UFW firewall rules
Documentation
use core::fmt;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Protocol {
    Tcp,
    Udp,
    Both,
}

impl Protocol {
    pub fn as_str(&self) -> &'static str {
        match self {
            Protocol::Tcp => "tcp",
            Protocol::Udp => "udp",
            Protocol::Both => "both",
        }
    }

    pub fn is_tcp(&self) -> bool {
        matches!(self, Protocol::Tcp)
    }

    pub fn is_udp(&self) -> bool {
        matches!(self, Protocol::Udp)
    }
}

impl fmt::Display for Protocol {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.as_str())
    }
}