rs-zero 0.2.12

Rust-first microservice framework inspired by go-zero engineering practices
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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))
    }
}