【发布时间】:2015-09-09 07:23:04
【问题描述】:
mod simulation;
use simulation::factory::FactoryType;
在main.rs 中工作正常,但在simulation/factory.rs 内的文档测试中却不行:
impl product_type::ProductType for FactoryType {
/// Lorem Ipsum
///
/// # Examples
///
/// ```
/// use simulation::factory::FactoryType;
///
/// ...
/// ```
fn human_id(&self) -> &String {
...
}
}
cargo test 给了我错误
---- simulation::factory::human_id_0 stdout ----
<anon>:2:9: 2:19 error: unresolved import `simulation::factory::FactoryType`. Maybe a missing `extern crate simulation`?
<anon>:2 use simulation::factory::FactoryType;
^~~~~~~~~~
error: aborting due to previous error
thread 'simulation::factory::human_id_0' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:192
如何让 doctest 工作?
【问题讨论】:
-
如果你正在创建一个二进制文件(例如,如果一个有
src/main.rs而不是src/lib.rs)那么你不能在 doctest 中使用它的函数:doc tests import the crate they' re from 作为一个库(如果它是一个)。 -
请在寻求帮助时花时间创建MCVE。正如您目前所说的那样,我们必须进行大量猜测才能确切知道存在什么。
标签: rust rust-cargo