rust - 错误 E0412:导入 tokio::sync 时使用未声明的 crate 或模块 `tokio`
问题描述
在我的 rust 项目中,cargo 抱怨使用 tokio::sync 时使用的类型不在范围内:
use tokio::sync::RwLock;
| ^^^^^ use of undeclared crate or module `tokio`
但它显然在范围内:
use tokio::sync::RwLock;
#[derive(Deserialize, Serialize)]
pub struct MyStruct {
some_field: RwLock<SomeType>
}
根据文档,同步模块只有在启用sync
功能标志后才可用,我已经显式和隐式地完成了:
tokio = { version = "0.3", features = ["macros", "sync"] }
tokio = { version = "0.3", features = ["full"] }
但它不适用于任何一个。
解决方案
我没有注意到我在 dev-dependencies 下只有 tokio,这就是 cargo 无法编译项目的原因。
推荐阅读
- c# - System.IO 异常“该进程无法访问该文件,因为它正被另一个进程使用。”
- reactjs - React setstate 回调在初始使用后不起作用
- node.js - 服务应该抛出异常?(网络 API)
- angular - catchError 上的拦截器中的无限循环
- java - 试图从只有一行的网站获取字符串
- python - 使用 sqlite OperationalError 创建函数:没有这样的列
- tensorflow - 在张量流中使用神经网络进行二进制分类无法学习
- r - Selenium 不再适用于 R
- spring-boot - JPA:多对多问题 - Spring Boot 项目
- javascript - 为什么 jQuery .one 函数只在向下滚动时起作用?