56 lines
1.3 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, AFPluginEventRequest},
2021-06-27 15:11:41 +08:00
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;
}
pub trait AFPluginServiceFactory<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(crate) struct ServiceRequest {
req: AFPluginEventRequest,
2021-06-24 16:32:36 +08:00
payload: Payload,
}
impl ServiceRequest {
pub(crate) fn new(req: AFPluginEventRequest, payload: Payload) -> Self {
2022-01-23 12:14:00 +08:00
Self { req, payload }
}
2021-06-24 23:37:45 +08:00
2021-06-24 16:32:36 +08:00
#[inline]
pub(crate) fn into_parts(self) -> (AFPluginEventRequest, Payload) {
2022-01-23 12:14:00 +08:00
(self.req, self.payload)
}
2021-06-24 16:32:36 +08:00
}
2021-06-27 15:11:41 +08:00
pub struct ServiceResponse {
request: AFPluginEventRequest,
2021-06-27 15:11:41 +08:00
response: EventResponse,
2021-06-24 16:32:36 +08:00
}
2021-06-27 15:11:41 +08:00
impl ServiceResponse {
pub fn new(request: AFPluginEventRequest, response: EventResponse) -> Self {
2022-01-23 12:14:00 +08:00
ServiceResponse { request, response }
}
2021-06-26 23:52:03 +08:00
pub fn into_parts(self) -> (AFPluginEventRequest, EventResponse) {
2022-01-23 12:14:00 +08:00
(self.request, self.response)
}
2021-06-24 16:32:36 +08:00
}