【发布时间】:2021-01-25 10:02:08
【问题描述】:
我有这个模块:
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::admin_index具有什么样的价值?没有参数的函数?一个参数的函数?未来?impl Responder? -
此时不应该有任何问题。这里的问题是编译器声称 basicAdapters 是未声明的,尽管它的声明很明显。
标签: rust