summaryrefslogtreecommitdiff
path: root/webhook/src/handler/make_service.rs
blob: 96b203dd9510c9825487a6548ee4d5e100e2a5b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::{future::{Ready, ready}, sync::Arc, task::{Context, Poll}};
use hyper::service::Service;
use nats::Connection;
use crate::config::Config;
use super::handler::HandlerService;


pub struct MakeSvc {
    pub settings: Config,
    pub nats: Arc<Connection>,
}

impl<T> Service<T> for MakeSvc {
    type Response = HandlerService;
    type Error = std::io::Error;
    type Future = Ready<Result<Self::Response, Self::Error>>;

    fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
        Ok(()).into()
    }

    fn call(&mut self, _: T) -> Self::Future {
        ready(Ok(HandlerService {
            config: self.settings.clone(),
            nats: self.nats.clone(),
        }))
    }
}