use std::{future::Future, pin::Pin};
use crate::mqtt::{MqttMessage, MqttResult};
pub trait MqttHandler: Send + Sync + 'static {
fn handle(&self, message: MqttMessage) -> Pin<Box<dyn Future<Output = MqttResult<()>> + Send>>;
}
impl<F, Fut> MqttHandler for F
where
F: Fn(MqttMessage) -> Fut + Send + Sync + 'static,
Fut: Future<Output = MqttResult<()>> + Send + 'static,
{
fn handle(&self, message: MqttMessage) -> Pin<Box<dyn Future<Output = MqttResult<()>> + Send>> {
Box::pin((self)(message))
}
}