46 lines
1.2 KiB
Rust
Raw Normal View History

2021-06-24 16:32:36 +08:00
use std::future::Future;
2021-06-25 23:53:13 +08:00
use crate::{
request::{payload::Payload, FlowyRequest},
response::{data::ResponseData, FlowyResponse},
};
2021-06-24 16:32:36 +08:00
pub trait Service<Request> {
type Response;
type Error;
type Future: Future<Output = Result<Self::Response, Self::Error>>;
fn call(&self, req: Request) -> Self::Future;
}
2021-06-25 23:53:13 +08:00
pub trait ServiceFactory<Request> {
2021-06-24 16:32:36 +08:00
type Response;
type Error;
2021-06-25 23:53:13 +08:00
type Service: Service<Request, Response = Self::Response, Error = Self::Error>;
2021-06-24 16:32:36 +08:00
type Config;
2021-06-25 23:53:13 +08:00
type Future: Future<Output = Result<Self::Service, Self::Error>>;
2021-06-24 16:32:36 +08:00
fn new_service(&self, cfg: Self::Config) -> Self::Future;
}
pub struct ServiceRequest {
req: FlowyRequest,
payload: Payload,
}
impl ServiceRequest {
2021-06-25 23:53:13 +08:00
pub fn new(req: FlowyRequest, payload: Payload) -> Self { Self { req, payload } }
2021-06-24 23:37:45 +08:00
2021-06-24 16:32:36 +08:00
#[inline]
2021-06-25 23:53:13 +08:00
pub fn into_parts(self) -> (FlowyRequest, Payload) { (self.req, self.payload) }
2021-06-24 16:32:36 +08:00
}
pub struct ServiceResponse<T = ResponseData> {
request: FlowyRequest,
response: FlowyResponse<T>,
}
impl<T> ServiceResponse<T> {
2021-06-25 23:53:13 +08:00
pub fn new(request: FlowyRequest, response: FlowyResponse<T>) -> Self { ServiceResponse { request, response } }
2021-06-24 16:32:36 +08:00
}