summaryrefslogtreecommitdiffstats
path: root/src/update.rs
blob: b2471da9921e735081602d6e63a7b0973be1e35b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::client::Client;
use futures::future::BoxFuture;
use serde_json::value::Value;
use std::future::Future;

pub trait Handler: Send + Sync + 'static {
    fn handle_json(&self, _: Client, _: Value) -> BoxFuture<'static, ()>;
}

impl<C, F> Handler for C
where
    C: Send + Sync + 'static + Fn(Client, Value) -> F,
    F: Future<Output = ()> + 'static + Send,
{
    fn handle_json(&self, client: Client, req: Value) -> BoxFuture<'static, ()> {
        Box::pin((*self)(client, req))
    }
}