`actix_web::Scope` 没有实现 `Clone` 特征

jav*_*bat 3 routes rust actix-web

我想在范围内对我的应用程序路由进行分组,以便将来可以根据域分隔它们的文件位置。我想做的是转换

HttpServer::new(move || App::new().app_data(app_state.clone()).service(delete_comment).service(update_comment).service(get_comments).service(create_comment))
        .bind(("127.0.0.1", 8080))?
        .run()
        .await
Run Code Online (Sandbox Code Playgroud)

到:

let comment_scope =  web::scope("/comments").service(delete_comment).service(update_comment).service(get_comments).service(create_comment);
HttpServer::new(move || App::new().app_data(app_state.clone()).service(comment_scope))
        .bind(("127.0.0.1", 8080))?
        .run()
        .await
Run Code Online (Sandbox Code Playgroud)

但它一直告诉我该特征Clone尚未实现actix_web::Scope。我怎样才能解决这个问题?

jav*_*bat 5

您只需将comment_scope声明移至new关闭状态即可:

HttpServer::new(move || {
      
        let comment_scope = web::scope("/comments")
        .service(delete_comment)
        .service(update_comment)
        .service(get_comments)
        .service(create_comment);

        App::new()
            .service(comment_scope)
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
Run Code Online (Sandbox Code Playgroud)