-
Hi - quite simply, why doesn't the following code work: use axum::{Json, Router};
use axum::routing::get;
use serde_json::{json, Value};
pub(crate) fn start() -> axum::routing::Router {
let app = Router::new()
.route("translations.json", get(handle_locale));
app
}
fn handle_locale() -> Json<HashMap<String,String>> {
let m = HashMap::default();
Json(m)
}
The error is as follows: error[E0277]: the trait bound `fn() -> axum::Json<HashMap<std::string::String, std::string::String>> {handle_locale}: Handler<_, _>` is not satisfied
--> src/i18n/mod.rs:19:41
|
19 | .route("translations.json", get(handle_locale));
| --- ^^^^^^^^^^^^^ the trait `Handler<_, _>` is not implemented for `fn() -> axum::Json<HashMap<std::string::String, std::string::String>> {handle_locale}`
| |
| required by a bound introduced by this call
|
note: required by a bound in `axum::routing::get`
--> /Users/coliny/.cargo/registry/src/github.com-1ecc6299db9ec823/axum-0.4.2/src/routing/method_routing.rs:394:1
|
394 | top_level_handler_fn!(get, GET);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `axum::routing::get`
= note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info) I get the same error if I return Help :-) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
If you run into |
Beta Was this translation helpful? Give feedback.
-
I have handler in my code: but if I made Json as second parameter, it works fine |
Beta Was this translation helpful? Give feedback.
If you run into
Handler<_, _> is not implemented
errors, enable axum'smacros
feature and annotate your handler with#[axum::debug_handler]
. It will give you much better error messages. In this case it looks like you simply forgot to make your handler functionasync
.