访问 impl 模块时获取"use of undeclared type or module"



我有这个模块:

src/adapters.rs

use super::db::{init_connection, models};
use actix_web::Responder;
use diesel::r2d2::{ConnectionManager, Pool};
use diesel::MysqlConnection;
pub struct Basic {
pool: Pool<ConnectionManager<MysqlConnection>>,
}
impl Basic {
pub fn new() -> Basic {
Basic {
pool: init_connection().unwrap(),
}
}
pub async fn admin_index(&self) -> impl Responder {
"API Admin"
}
}

我想从模块中调用实例方法admin_index:

src/routes.rs

像这样:

use actix_web::{web, HttpResponse, Responder};
use super::adapters::Basic;
pub fn create(app: &mut web::ServiceConfig) {
let basicAdapters = Basic::new();
app
.service(web::resource("/").to(|| HttpResponse::Ok().body("index")))
.service(
web::scope("/api")
.service(
bweb::scope("/admin")
.route("/", web::get().to(basicAdapters::admin_index))
)
}

但我一直得到:

error[E0433]: failed to resolve: use of undeclared type or module `basicAdapters`
.route("/", web::get().to(basicAdapters::admin_index))
^^^^^^^^^^^^^ use of undeclared type or module `basicAdapters`

我不明白为什么我会收到这个错误消息,因为basicAdapters显然是由声明的

let basicAdapters = Basic::new();

感谢您的帮助。

::是命名空间解析运算符,而basicAdapters不是命名空间。

要对值调用方法,请使用.运算符:

web::get().to(basicAdapters.admin_index())

最新更新