我正在尝试用闭包声明我的路线:
use mongodb::Client;
pub fn get_user_routes(client: Client) -> Router {
let controller = controller::UserController::new(client);
let handler = handlers::UserHandler::new(controller);
router!(
index: get "/" => move |r: &mut Request| handler.index(r),
show: get "/:id" => move |r: &mut Request| handler.show(r),
)
}
我收到此错误,我无法Copy
为我实现该特征,UserController
因为mongodb::Client
它没有实现它(它是一个Arc
)。
error[E0382]: capture of moved value: `handler`
--> src/api/users/mod.rs:17:57
|
16 | index: get "/" => move |r: &mut Request| handler.index(r),
| ---------------------- value moved (into closure) here
17 | show: get "/:id" => move |r: &mut Request| handler.show(r),
| ^^^^^^^ value captured here after move
|
= note: move occurs because `handler` has type `api::users::handlers::UserHandler`, which does not implement the `Copy` trait
我UserHandler
只有一个UserController
和一个UserController
,一个mongodb::Client
。