启用tunio的async-tokio特性后,无法导入DefaultAsyncInterface怎么办?
问题
我尝试使用tunio库依赖tokio特性的DefaultAsyncInterface,已在Cargo.toml中为tunio开启async-tokio特性:
[dependencies] env_logger = "0.10.0" etherparse = "0.13.0" futures = "0.3.25" netconfig = "0.4.0" tokio = { version = "1.24.1", features = ["full"] } tunio = { version = "0.3.0", features = ["async-tokio"] }
通过use tunio::{DefaultDriver,DefaultAsyncInterface};导入时,构建出现错误:
error[E0432]: unresolved import `tunio::DefaultAsyncInterface` --> src/main.rs:7:27 | 7 | use tunio::{DefaultDriver,DefaultAsyncInterface}; | ^^^^^^^^^^^^^^^^^^^^^ | | | no `DefaultAsyncInterface` in the root | help: a similar name exists in the module: `DefaultInterface`
看起来async-tokio特性未生效,请问问题出在哪里?
解决方法
- 版本不匹配:你使用的tunio 0.3.0版本中,
DefaultAsyncInterface并不在根模块直接导出,且该版本的async-tokio特性对应的异步接口结构与你参考的仓库代码不一致——你参考的是仓库特定提交的代码,而该内容并未包含在已发布的0.3.0版本中。 - 修正导入路径:在tunio 0.3.0版本中,开启
async-tokio特性后,异步接口需要从tunio::async子模块导入,正确的导入语句应为:use tunio::{DefaultDriver, async::DefaultAsyncInterface}; - 清理缓存确保特性生效:如果修改导入后仍有问题,可清理Cargo缓存再重新构建,执行命令:
cargo clean && cargo build
内容的提问来源于stack exchange,提问作者Ariyan Eghbal
相关产品推荐
相关产品推荐

