1use crate::{Error, ErrorInternal, Result, ffi};
10
11#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
13#[repr(u8)]
14pub enum Direction {
15 #[default]
16 Any = ffi::pfvar::PF_INOUT as u8,
17 In = ffi::pfvar::PF_IN as u8,
18 Out = ffi::pfvar::PF_OUT as u8,
19}
20
21impl From<Direction> for u8 {
22 fn from(direction: Direction) -> Self {
23 direction as u8
24 }
25}
26
27impl TryFrom<u8> for Direction {
28 type Error = crate::Error;
29
30 fn try_from(direction: u8) -> Result<Self> {
31 match direction {
32 v if v == Direction::Any as u8 => Ok(Direction::Any),
33 v if v == Direction::In as u8 => Ok(Direction::In),
34 v if v == Direction::Out as u8 => Ok(Direction::Out),
35 other => Err(Error::from(ErrorInternal::InvalidDirection(other))),
36 }
37 }
38}