use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum QoS {
AtMostOnce = 0,
AtLeastOnce = 1,
ExactlyOnce = 2,
}
impl QoS {
#[cfg(feature = "rumqttc")]
pub fn to_rumqttc(self) -> rumqttc::QoS {
match self {
| QoS::AtMostOnce => rumqttc::QoS::AtMostOnce,
| QoS::AtLeastOnce => rumqttc::QoS::AtLeastOnce,
| QoS::ExactlyOnce => rumqttc::QoS::ExactlyOnce,
}
}
#[cfg(feature = "paho-mqtt")]
pub fn to_paho_mqtt(self) -> paho_mqtt::QoS {
match self {
| QoS::AtMostOnce => paho_mqtt::QoS::AtMostOnce,
| QoS::AtLeastOnce => paho_mqtt::QoS::AtLeastOnce,
| QoS::ExactlyOnce => paho_mqtt::QoS::ExactlyOnce,
}
}
#[cfg(feature = "ntex-mqtt")]
pub fn to_ntex_mqtt(self) -> ntex_mqtt::QoS {
match self {
| QoS::AtMostOnce => ntex_mqtt::QoS::AtMostOnce,
| QoS::AtLeastOnce => ntex_mqtt::QoS::AtLeastOnce,
| QoS::ExactlyOnce => ntex_mqtt::QoS::ExactlyOnce,
}
}
}
#[cfg(feature = "rumqttc")]
impl From<rumqttc::QoS> for QoS {
fn from(qos: rumqttc::QoS) -> Self {
match qos {
| rumqttc::QoS::AtMostOnce => QoS::AtMostOnce,
| rumqttc::QoS::AtLeastOnce => QoS::AtLeastOnce,
| rumqttc::QoS::ExactlyOnce => QoS::ExactlyOnce,
}
}
}
#[cfg(feature = "paho-mqtt")]
impl From<paho_mqtt::QoS> for QoS {
fn from(qos: paho_mqtt::QoS) -> Self {
match qos {
| paho_mqtt::QoS::AtMostOnce => QoS::AtMostOnce,
| paho_mqtt::QoS::AtLeastOnce => QoS::AtLeastOnce,
| paho_mqtt::QoS::ExactlyOnce => QoS::ExactlyOnce,
}
}
}
#[cfg(feature = "ntex-mqtt")]
impl From<ntex_mqtt::QoS> for QoS {
fn from(qos: ntex_mqtt::QoS) -> Self {
match qos {
| ntex_mqtt::QoS::AtMostOnce => QoS::AtMostOnce,
| ntex_mqtt::QoS::AtLeastOnce => QoS::AtLeastOnce,
| ntex_mqtt::QoS::ExactlyOnce => QoS::ExactlyOnce,
}
}
}
impl fmt::Display for QoS {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
| QoS::AtMostOnce => write!(f, "QoS0"),
| QoS::AtLeastOnce => write!(f, "QoS1"),
| QoS::ExactlyOnce => write!(f, "QoS2"),
}
}
}