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);
}
我该如何将一个返回
impl Trait
(或在我这种情况下返回 impl Responder
)的参数传递给函数?该错误提示为:“
impl Trait
” 不允许出现在函数和内部方法的返回类型之外。
impl Trait
的情况。 - michael_j_ward