├── Cargo.lock
├── Cargo.toml
├── src
│    └── model.rs
└── examples
    └── client
           └──mod.rs

我想使用一个名为Client的结构,它存在于examples > client > mod.rs文件中的model.rs中。我的包名是CratesTest中的Cargo.toml
我在我的model.rs里试过这个:
extern crate CratesTest;

fn main() {
    CratesTest::Client::new(/*snip*/)
}

我知道错误:
error[E0433]: failed to resolve: could not find `Client` in `CratesTest`
let client = CratesTest::Client::new(...
                         ^^^^^^ could not find `Client` in `CratesTest`

我也尝试过使用mod client;,但它没有将其纳入范围。

最佳答案

我想说这里有一个依赖关系的倒置:你的示例依赖于你的库是合理的,但是为什么你的库依赖于这些示例呢?正如Denys Séguret指出的,the documentation指出:
示例下的文件是库提供的功能的示例使用
所以示例使用库,而不是相反。

10-06 08:22
查看更多