50 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::{
2021-06-27 15:11:41 +08:00
request::{payload::Payload, EventRequest},
response::EventResponse,
2021-06-25 23:53:13 +08:00
};
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>;
type Context;
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::Context) -> Self::Future;
2021-06-24 16:32:36 +08:00
}
pub struct ServiceRequest {
2021-06-27 15:11:41 +08:00
req: EventRequest,
2021-06-24 16:32:36 +08:00
payload: Payload,
}
impl ServiceRequest {
2021-06-27 15:11:41 +08:00
pub fn new(req: EventRequest, 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-27 15:11:41 +08:00
pub fn into_parts(self) -> (EventRequest, Payload) { (self.req, self.payload) }
2021-06-24 16:32:36 +08:00
}
2021-06-27 15:11:41 +08:00
pub struct ServiceResponse {
request: EventRequest,
response: EventResponse,
2021-06-24 16:32:36 +08:00
}
2021-06-27 15:11:41 +08:00
impl ServiceResponse {
pub fn new(request: EventRequest, response: EventResponse) -> Self {
ServiceResponse { request, response }
}
2021-06-26 23:52:03 +08:00
2021-06-27 15:11:41 +08:00
pub fn into_parts(self) -> (EventRequest, EventResponse) { (self.request, self.response) }
2021-06-24 16:32:36 +08:00
}