use crate::{Error, ErrorInternal, Result, ffi};
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum Direction {
#[default]
Any = ffi::pfvar::PF_INOUT as u8,
In = ffi::pfvar::PF_IN as u8,
Out = ffi::pfvar::PF_OUT as u8,
}
impl From<Direction> for u8 {
fn from(direction: Direction) -> Self {
direction as u8
}
}
impl TryFrom<u8> for Direction {
type Error = crate::Error;
fn try_from(direction: u8) -> Result<Self> {
match direction {
v if v == Direction::Any as u8 => Ok(Direction::Any),
v if v == Direction::In as u8 => Ok(Direction::In),
v if v == Direction::Out as u8 => Ok(Direction::Out),
other => Err(Error::from(ErrorInternal::InvalidDirection(other))),
}
}
}