如何在库本身中使用库示例中的代码?

├── 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;,但它没有将其纳入范围。

allenyu58 回答:如何在库本身中使用库示例中的代码?

我要说的是这里有一个依赖关系的倒置:让示例依赖于您的库是合理的,但是为什么您的库依赖于示例呢?正如DenysSéguret所指出的,the documentation指出:

  

示例下的文件是该库提供的功能的示例用途

所以示例使用库,而不是反向库。

本文链接:https://www.f2er.com/3153308.html

大家都在问