Skip to main content

alux_http_text/
handler.rs

1//! Records what one endpoint means: the handler it names and the types it relates.
2
3use alux_ext::{ApplyAlg, HandlerContextAlg, OperationAlg};
4use alux_http::{HandlerAlg, HandlerEndpointAlg, OutputAlg, OutputKindAlg};
5use core::any::type_name;
6use std::sync::Arc;
7
8/// Carries interpreted endpoint type information.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct TextEndpoint {
11    pub(crate) handler: &'static str,
12    pub(crate) inputs: &'static str,
13    pub(crate) args: &'static str,
14    pub(crate) result: &'static str,
15    pub(crate) transform: &'static str,
16    pub(crate) output: &'static str,
17}
18
19/// Interprets typed APIs as text descriptions.
20#[derive(Debug, Default)]
21pub struct TextHandlerImpl;
22
23impl HandlerAlg for TextHandlerImpl {
24    type Endpoint = TextEndpoint;
25}
26
27impl<Context, Inputs, Args, Transform, Answering, Answered, Output>
28    HandlerEndpointAlg<Context, Inputs, Args, Transform, Output> for TextHandlerImpl
29where
30    Transform: OutputKindAlg<TextHandlerImpl, Output, Transform = Answering>,
31    Answering: OutputAlg<Output, Output = Answered>,
32{
33    fn finish_handler<Handler>(&self, _handler: Handler) -> TextEndpoint
34    where
35        Handler: OperationAlg + ApplyAlg<Context, Args, Output = Output> + Send + Sync + 'static,
36    {
37        TextEndpoint {
38            handler: type_name::<Handler>(),
39            inputs: type_name::<Inputs>(),
40            args: type_name::<Args>(),
41            result: type_name::<Output>(),
42            transform: type_name::<Answering>(),
43            output: type_name::<Answered>(),
44        }
45    }
46}
47
48impl<Context> HandlerContextAlg<Context> for TextHandlerImpl
49where
50    Context: Send + Sync + 'static,
51{
52    type Handle = Arc<Context>;
53}