use std::fmt;
#[cfg(test)]
mod direction_test;
#[derive(Default, Debug, PartialEq, Eq, Clone)]
pub enum Direction {
#[default]
Unspecified = 0,
SendRecv = 1,
SendOnly = 2,
RecvOnly = 3,
Inactive = 4,
}
const DIRECTION_SEND_RECV_STR: &str = "sendrecv";
const DIRECTION_SEND_ONLY_STR: &str = "sendonly";
const DIRECTION_RECV_ONLY_STR: &str = "recvonly";
const DIRECTION_INACTIVE_STR: &str = "inactive";
const DIRECTION_UNSPECIFIED_STR: &str = "Unspecified";
impl fmt::Display for Direction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
Direction::SendRecv => DIRECTION_SEND_RECV_STR,
Direction::SendOnly => DIRECTION_SEND_ONLY_STR,
Direction::RecvOnly => DIRECTION_RECV_ONLY_STR,
Direction::Inactive => DIRECTION_INACTIVE_STR,
_ => DIRECTION_UNSPECIFIED_STR,
};
write!(f, "{s}")
}
}
impl Direction {
pub fn new(raw: &str) -> Self {
match raw {
DIRECTION_SEND_RECV_STR => Direction::SendRecv,
DIRECTION_SEND_ONLY_STR => Direction::SendOnly,
DIRECTION_RECV_ONLY_STR => Direction::RecvOnly,
DIRECTION_INACTIVE_STR => Direction::Inactive,
_ => Direction::Unspecified,
}
}
}