'`impl Trait` not allowed outside of function and inherent method return types
trait Responder{
}
struct App;
impl App {
fn new() -> Self {
Self {}
}
fn service<T, B>(&self, routes: T) -> Self where T: Fn()-> impl Responder {
Self {}
}
}
struct Routes {
data:String,
}
impl Responder for Routes{
}
fn routes() -> impl Responder {
Routes {
data: "Hello".to_string()
}
}
fn main() {
// let new_routes = routes;
App::new().service(routes);
}
How do I pass a function a parameter that return impl Trait or in my case impl Responder.
The error that it gives is: impl Trait not allowed outside of function and inherent method return types.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
