#[derive(Debug, Copy, Eq, PartialEq, Clone)]
pub enum MsgType {
Con = 0,
Non = 1,
Ack = 2,
Res = 3,
}
impl MsgType {
pub fn from(tt: u8) -> MsgType {
MsgType::try_from(tt).expect("Invalid message type")
}
pub fn try_from(tt: u8) -> Option<MsgType> {
match tt {
0 => Some(MsgType::Con),
1 => Some(MsgType::Non),
2 => Some(MsgType::Ack),
3 => Some(MsgType::Res),
_ => None,
}
}
pub fn is_non(self) -> bool {
self == MsgType::Non
}
pub fn is_con(self) -> bool {
self == MsgType::Con
}
pub fn is_ack(self) -> bool {
self == MsgType::Ack
}
pub fn is_res(self) -> bool {
self == MsgType::Res
}
}
impl Default for MsgType {
fn default() -> Self {
MsgType::Con
}
}