-
Bug ReportRecently started to migrate to Axum 0.7 Compile error:
Version
PlatformWindows (64-bit) Crates
DescriptionThe snippet of code: use axum::{
handler::HandlerWithoutStateExt,
http::{HeaderValue, StatusCode},
middleware::from_fn_with_state,
Router,
};
use tower::ServiceExt;
use tower_http::services::ServeDir;
pub fn setup_static_fs_handler() -> Router {
async fn not_found() -> (StatusCode, &'static str) {
(StatusCode::NOT_FOUND, "Resource not found")
}
let not_found_service = not_found.into_service();
let serve = ServeDir::new("data")
.precompressed_gzip()
.not_found_service(not_found_service)
.map_response(|mut res| {
if res.status() != StatusCode::NOT_FOUND {
res.headers_mut()
.insert("Cache-Control", HeaderValue::from_static("max-age=3600"));
}
res
});
Router::new().nest_service("/", serve)
} |
Beta Was this translation helpful? Give feedback.
Answered by
jplatte
Mar 11, 2024
Replies: 1 comment 3 replies
-
Looks like the Rust compiler can't infer the body type for the request. Where exactly is the error message pointing? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a really tricky one! I played around with it locally to find a solution. You can add a
map_request
beforemap_response
to explicitly specify the request body type that the compiler fails to infer:There are other solutions, but I found them to be way too complicated. I would love if we could do something about this being so weird, but I'm not really certain how this could be fixed in tower / axum.