rs-zero 0.2.24

Rust-first microservice framework inspired by go-zero engineering practices
Documentation
use std::{future::Future, pin::Pin};

use crate::mqtt::{MqttContext, MqttMessage, MqttResult};

pub trait MqttHandler: Send + Sync + 'static {
    fn handle(&self, message: MqttMessage) -> Pin<Box<dyn Future<Output = MqttResult<()>> + Send>>;

    fn handle_with_context(
        &self,
        _context: MqttContext,
        message: MqttMessage,
    ) -> Pin<Box<dyn Future<Output = MqttResult<()>> + Send>> {
        self.handle(message)
    }
}

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))
    }
}