Closed
Description
When I define very complex routes with axum web framework, the compilation time increases a lot. This should be rustc's problem.
Example: https://github.com/paulzhang5511/axum-compile-slow
let app = Router::new()
.nest(
"/",
axum::service::get(ServeDir::new("./publish").append_index_html_on_directories(true))
.handle_error(|error: std::io::Error| {
Ok::<_, std::convert::Infallible>((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Unhandled internal error: {}", error),
))
}),
)
.nest(
"/upload",
axum::service::get(ServeDir::new("./upload").append_index_html_on_directories(false))
.handle_error(|error: std::io::Error| {
tracing::debug!("{:?}", error);
Ok::<_, std::convert::Infallible>((
StatusCode::INTERNAL_SERVER_ERROR,
"read file error".to_string(),
))
}),
)
.nest(
"/api",
Router::new()
.route("/pay/pay_params", post(handle))
.route("/pay/transfer_info", post(handle))
.route("/upload/image", post(handle))
.nest(
"/user",
Router::new()
.route("/list", get(handle))
.route("/create", post(handle))
.route("/login", post(handle))
.route("/info", get(handle))
.route("/update_password", get(handle))
.route("/money", get(handle)),
)
.nest(
"/order",
Router::new()
.route("/create", post(handle))
.route("/all", get(handle))
.route("/list", get(handle)),
)
.nest(
"/product",
Router::new()
.route("/list", get(handle))
.route("/home", get(handle))
.route("/create", post(handle))
.route("/update/:id", post(handle))
.route("/delete", post(handle))
.route("/detail", get(handle))
.route("/earnings/create", post(handle))
.route("/earnings/delete", post(handle))
.route("/earnings/find", get(handle))
.boxed(),
)
.layer(AsyncFilterLayer::new(map_request))
.layer(AndThenLayer::new(map_response))
.handle_error(|error: BoxError| {
if error.is::<tower::timeout::error::Elapsed>() {
Ok::<_, Infallible>((
StatusCode::REQUEST_TIMEOUT,
"request took too long".to_string(),
))
} else {
tracing::debug!("{:?}", error);
Ok::<_, Infallible>((
StatusCode::INTERNAL_SERVER_ERROR,
"Unhandled internal error".to_string(),
))
}
}),
)
.layer(MapResponseLayer::new(map_404))
.layer(
ServiceBuilder::new()
.timeout(Duration::from_secs(15))
.layer(TraceLayer::new_for_http())
.layer(AddExtensionLayer::new(pool))
.into_inner(),
);
Meta
rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-unknown-linux-gnu
release: 1.54.0
LLVM version: 12.0.1