61 lines
1.5 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},
response::AFPluginEventResponse,
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>>;
2021-06-24 16:32:36 +08:00
fn call(&self, req: Request) -> Self::Future;
2021-06-24 16:32:36 +08:00
}
2022-12-01 10:59:22 +08:00
/// Returns a future that can handle the request. For the moment, the request will be the
/// `AFPluginRequest`
pub trait AFPluginServiceFactory<Request> {
type Response;
type Error;
type Service: Service<Request, Response = Self::Response, Error = Self::Error>;
type Context;
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 {
event_state: AFPluginEventRequest,
payload: Payload,
2021-06-24 16:32:36 +08:00
}
impl ServiceRequest {
pub(crate) fn new(event_state: AFPluginEventRequest, payload: Payload) -> Self {
Self {
event_state,
payload,
2022-01-23 12:14:00 +08:00
}
}
2021-06-24 23:37:45 +08:00
#[inline]
pub(crate) fn into_parts(self) -> (AFPluginEventRequest, Payload) {
(self.event_state, self.payload)
}
2021-06-24 16:32:36 +08:00
}
2021-06-27 15:11:41 +08:00
pub struct ServiceResponse {
request: AFPluginEventRequest,
response: AFPluginEventResponse,
2021-06-24 16:32:36 +08:00
}
2021-06-27 15:11:41 +08:00
impl ServiceResponse {
pub fn new(request: AFPluginEventRequest, response: AFPluginEventResponse) -> Self {
ServiceResponse { request, response }
}
2021-06-26 23:52:03 +08:00
pub fn into_parts(self) -> (AFPluginEventRequest, AFPluginEventResponse) {
(self.request, self.response)
}
2021-06-24 16:32:36 +08:00
}