Skip to main content

sword_layers/
lib.rs

1#![allow(clippy::new_ret_no_self)]
2
3use std::any::Any;
4use thisconfig::Config;
5
6#[cfg(feature = "body-limit")]
7pub mod body_limit {
8    mod grpc;
9    mod web;
10
11    pub use grpc::*;
12    pub use web::*;
13}
14
15#[cfg(feature = "compression")]
16pub mod compression;
17
18#[cfg(feature = "cookies")]
19pub mod cookies {
20    pub use tower_cookies::*;
21}
22
23#[cfg(feature = "cors")]
24pub mod cors;
25
26#[cfg(feature = "helmet")]
27pub mod helmet;
28
29#[cfg(feature = "not-found")]
30pub mod not_found;
31
32pub mod prelude;
33
34#[cfg(feature = "body-limit")]
35pub(crate) type ServiceLayer<Inner, Outer> = tower::ServiceBuilder<
36    tower_layer::Stack<Inner, tower_layer::Stack<Outer, tower_layer::Identity>>,
37>;
38
39#[cfg(any(feature = "body-limit", feature = "req-timeout"))]
40pub(crate) type MapResponseLayer = tower::util::MapResponseLayer<ResponseFnMapper>;
41#[cfg(any(feature = "body-limit", feature = "req-timeout"))]
42pub(crate) type ResponseFnMapper =
43    fn(axum::response::Response<axum::body::Body>) -> axum::response::Response<axum::body::Body>;
44
45#[cfg(feature = "request-id")]
46pub mod request_id;
47
48#[cfg(feature = "servedir")]
49pub mod servedir;
50
51#[cfg(feature = "tracing")]
52pub mod tracing;
53
54#[cfg(feature = "req-timeout")]
55pub mod timeout;
56
57pub trait DisplayConfig {
58    fn display(&self);
59}
60
61type LayerRegistrarFn = fn(&Config) -> Box<dyn FnOnce(&mut dyn Any) + Send>;
62
63pub struct SwordLayerRegistrar {
64    pub name: &'static str,
65    pub register: LayerRegistrarFn,
66    pub display: fn(&Config),
67}
68
69inventory::collect!(SwordLayerRegistrar);
70
71type ServiceRegistrarFn = fn(&Config) -> Box<dyn FnOnce(&mut dyn Any) + Send>;
72
73pub struct SwordServiceRegistrar {
74    pub name: &'static str,
75    pub register: ServiceRegistrarFn,
76    pub display: fn(&Config),
77}
78
79inventory::collect!(SwordServiceRegistrar);