Skip to main content

alux_http/
output.rs

1/// Transforms an inferred handler result into its portable API output.
2///
3/// Converter families are selected from an endpoint's output kind. The handler
4/// result supplies `From`, so API declarations never repeat it.
5pub trait OutputAlg<From> {
6    /// The transport value produced from the semantic handler result.
7    type Output;
8
9    /// Converts a handler result into the declared API output.
10    fn output(from: From) -> Self::Output;
11}
12
13/// Selects the converter used for JSON API outputs.
14pub trait JsonOutAlg {
15    /// The JSON converter selected for `From`.
16    type Json<From>: OutputAlg<From>;
17}
18
19/// Selects the converter used for streamed file API outputs.
20pub trait FileOutAlg {
21    /// The streamed-file converter selected for `From`.
22    type File<From>: OutputAlg<From>;
23}
24
25/// Resolves a portable output kind through an interpreter.
26pub trait OutputKindAlg<Interpreter: ?Sized, From> {
27    /// The concrete converter chosen by `Interpreter` for this output kind.
28    type Transform: OutputAlg<From>;
29}
30
31/// Selects JSON output semantics.
32pub struct JsonOut;
33
34impl<Interpreter, From> OutputKindAlg<Interpreter, From> for JsonOut
35where
36    Interpreter: JsonOutAlg + ?Sized,
37{
38    type Transform = Interpreter::Json<From>;
39}
40
41/// Selects streamed-file output semantics.
42pub struct FileOut;
43
44impl<Interpreter, From> OutputKindAlg<Interpreter, From> for FileOut
45where
46    Interpreter: FileOutAlg + ?Sized,
47{
48    type Transform = Interpreter::File<From>;
49}