Can some rustlang fluent creature help me with an axum problem?

I want to write some middleware that reads a cookie, a header does some value choosing that it needs some configuration for and attached the result to the request.

Currently this is implemented using an axum middleware function with state that is passed through axum::middleware::from_fn_with_state to turn it into a layer, but I want to turn it into a Layer struct, but I keep running into type problems.

async fn middleware( State(arc_state): State<Arc<LanguageManifest>>, cookie_header: Option<TypedHeader<headers::Cookie>>, mut req: Request<Body>, next: Next, ) -> Response { […] }

#rustlang #axum

@slatian can you share a minimally reproducible example of the Layer struct version that doesn't compile?

@jplatte I was about to collect all relevant code snippets and then asked myself: What does axum actually do under the hood and it turns out replicating that was the solution.

I now have a tower service that directly calls into Cookie::decode() (which is a method it has because if the Header trait in the headers crate) … which was not easy to discover.

It works now in case you are interested, the code is public: https://codeberg.org/slatian/lib-humus/src/branch/main/src/language_extraction_layer.rs

So thanks for making me look in the right place 

lib-humus/src/language_extraction_layer.rs at main

lib-humus - Helps creating frontends for humans and computers using axum, Tera and toml.

Codeberg.org