use rumqttc::AsyncClient;
use crate::mqtt::{MqttError, MqttQoS, MqttResult};
#[derive(Debug, Clone)]
pub struct MqttPublisher {
client: AsyncClient,
}
impl MqttPublisher {
pub fn new(client: AsyncClient) -> Self {
Self { client }
}
pub async fn publish(
&self,
topic: impl Into<String>,
qos: MqttQoS,
payload: Vec<u8>,
) -> MqttResult<()> {
self.client
.try_publish(topic.into(), qos.into(), false, payload)
.map_err(|error| MqttError::Publish(error.to_string()))
}
}