finchers_core/endpoint/
endpoint.rs1use std::sync::Arc;
2
3use super::apply::ApplyRequest;
4use super::context::Context;
5use input::{Input, RequestBody};
6use task::Task;
7
8pub trait Endpoint: Send + Sync {
10 type Output;
12
13 type Task: Task<Output = Self::Output>;
15
16 fn apply(&self, cx: &mut Context) -> Option<Self::Task>;
19
20 fn apply_request(&self, input: &Input, body: RequestBody) -> ApplyRequest<Self::Task> {
22 super::apply::apply_request(self, input, body)
23 }
24}
25
26impl<'a, E: Endpoint> Endpoint for &'a E {
27 type Output = E::Output;
28 type Task = E::Task;
29
30 fn apply(&self, cx: &mut Context) -> Option<Self::Task> {
31 (*self).apply(cx)
32 }
33}
34
35impl<E: Endpoint> Endpoint for Box<E> {
36 type Output = E::Output;
37 type Task = E::Task;
38
39 fn apply(&self, cx: &mut Context) -> Option<Self::Task> {
40 (**self).apply(cx)
41 }
42}
43
44impl<E: Endpoint> Endpoint for Arc<E> {
45 type Output = E::Output;
46 type Task = E::Task;
47
48 fn apply(&self, cx: &mut Context) -> Option<Self::Task> {
49 (**self).apply(cx)
50 }
51}
52
53pub trait IntoEndpoint {
55 type Output;
57
58 type Endpoint: Endpoint<Output = Self::Output>;
60
61 fn into_endpoint(self) -> Self::Endpoint;
63}
64
65impl<E: Endpoint> IntoEndpoint for E {
66 type Output = E::Output;
67 type Endpoint = E;
68
69 #[inline]
70 fn into_endpoint(self) -> Self::Endpoint {
71 self
72 }
73}