hyper_fast/server/
service.rs1use std::sync::Arc;
2use std::sync::atomic::AtomicBool;
3
4use async_trait::async_trait;
5use http::Response;
6use hyper::Body;
7
8use crate::server::{ApiError, HttpRoute};
9
10lazy_static! {
11 pub static ref IN_ROTATION: AtomicBool = AtomicBool::new(true);
12 pub static ref SHUTDOWN: AtomicBool = AtomicBool::new(false);
13}
14
15#[async_trait]
16pub trait ServiceBuilder<T: Service, D: ServiceDaemon<T>>: Send + Sync {
17 async fn build(self) -> anyhow::Result<(T, Option<D>)>;
18}
19
20#[async_trait]
21pub trait Service: Send + Sync {
22 async fn api_handler<'a>(
23 &'a self,
24 body: Body,
25 route: &HttpRoute<'a>,
26 path: &[&str],
27 ) -> Result<Response<Body>, ApiError>;
28}
29
30#[async_trait]
31pub trait ServiceDaemon<T>: Send + Sync
32 where
33 T: Service,
34{
35 async fn start(&self, service: Arc<T>);
36}