-
I'm using DI similar to the example in the repo. However,I don't quite understand why we can't use here is the handler
and here is the error: I changed the code and use dynamic dispatch, it works fine. However, there's
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For the return type, the compiler can infer the concrete type based on the function body. For an pub async fn get_films<R>(State(repo): State<R>) -> impl IntoResponse
where
R: FilmRepo + Send + Sync
{
StatusCode::OK
}
Router::new()
.route("/", get_films::<FilmRepoImpl>) |
Beta Was this translation helpful? Give feedback.
For the return type, the compiler can infer the concrete type based on the function body. For an
impl Trait
argument, it is simply impossible for the compiler to infer the correct type. You can still have generic handlers, but you have to use a named generic parameter, and specify it when registering the handler: