use super::packets::PacketType;
macro_rules! panic_in_test {
($($args:expr),+) => {
if cfg!(test) {
panic!($($args),+)
} else {
::log::error!($($args),+);
}
};
}
macro_rules! def_enum_with_intos {
{ $(#[$($attrs:tt)*])* $vis:vis enum $enum:ident { $($(#[$($vattrs:tt)*])* $name:ident$(($type:ty))?),+ } } => {
$(#[$($attrs)*])*
$vis enum $enum
{
$($(#[$($vattrs)*])* $name$(($type))?),+
}
$($(
impl Into<$enum> for $type
{
fn into(self) -> $enum { $enum::$name(self) }
}
)?)+
};
}
pub(crate) use panic_in_test;
pub(crate) use def_enum_with_intos;
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct IdType
{
pub ty: PacketType,
pub id: u16
}
impl IdType
{
pub fn publish(id: u16) -> Self { Self { ty: PacketType::Publish, id } }
pub fn subscribe(id: u16) -> Self { Self { ty: PacketType::Subscribe, id } }
pub fn pub_rec(id: u16) -> Self { Self { ty: PacketType::PubRec, id } }
pub fn pub_rel(id: u16) -> Self { Self { ty: PacketType::PubRel, id } }
pub fn unsubscribe(id: u16) -> Self { Self { ty: PacketType::Unsubscribe, id } }
}