Rust 使用未声明的类型或模块“HttpResponse”:未在此范围内找到

Rust 使用未声明的类型或模块“HttpResponse”:未在此范围内找到,rust,rust-cargo,Rust,Rust Cargo,我必须承认,我很难理解Rust编译器的错误消息 我有这个模块: src/adapters.js use actix_web::{Responder, HttpResponse}; pub mod Basic { pub fn api_index() -> &'static str { "API" } pub fn admin_index() -> impl Responder { HttpRes

我必须承认,我很难理解Rust编译器的错误消息

我有这个模块:

src/adapters.js

use actix_web::{Responder, HttpResponse};

pub mod Basic {

    pub fn api_index() -> &'static str {
        "API"
    }

    pub fn admin_index() -> impl Responder {
        HttpResponse::Ok().body("hello world!")
    }

}
锈编译器一直告诉我何时使用

use crate::actix_web::{Responder, HttpResponse};
即:

请放心,crate::actix_web并没有丢失,因为我可以从main.rs运行简单的请求。当我想在自己的模块中使用actix_web模块时,问题就出现了

如果我有

use actix_web::{Responder, HttpResponse};
铁锈一直困扰着我:

error[E0433]: failed to resolve: use of undeclared type or module `HttpResponse`

HttpResponse::Ok().body("hello world!")
^^^^^^^^^^^^ not found in this scope



help: consider importing one of these items
use actix_web::HttpResponse;
use crate::adapters::HttpResponse;


E0432: unresolved import `crate::actix_web`  maybe a missing crate `actix_web`?
我的main.rs作为第一行,我还声明:

extern crate actix_web;
为了确保这一点,我还在adapters.rs模块的开头添加了“extern-crate-actix_-web;”。这也没有改变任何事情


我已经没有选择了,我不知道还能做什么。

基本上,您已经在适配器模块中创建了另一个模块Basic。因此Basic是适配器模块的子模块。在这种情况下,有两种方法可以访问外部板条箱

  • 在基本模块内导入外部板条箱模块
  • pub mod Basic{
    使用actix_web::{Responder,HttpResponse};
    发布fn api_index()->&'static str{
    “API”
    }
    pub fn admin_index()->impl响应程序{
    HttpResponse::Ok().body(“你好,世界!”)
    }
    }
    
  • 或者在外部模块模块中导入外部模块,并在内部模块中使用super关键字访问这些模块
  • 使用actix_web:{Responder,HttpResponse};
    基本版{
    发布fn api_index()->&'static str{
    “API”
    }
    pub fn admin_index()->impl super::Responder{
    super::HttpResponse::Ok().body(“你好,世界!”)
    }
    }
    
    extern crate actix_web;