我很难在我的库的文档示例中修复错误。我有像我的箱子一样的文件结构bignum
.
|-- Cargo.lock
|-- Cargo.toml
|-- examples
| |-- dat
| | `-- euler_13.dat
| |-- debug.rs
| `-- euler_13.rs
|-- README.md
|-- src
| |-- error.rs
| |-- inits.rs
| `-- lib.rs
在我的示例中,我的标题看起来像
// euler_13.rs
extern crate bignum;
use bignum::inits::Zero;
// ...
这可以编译并且效果很好,但是现在当我在我的文档中编写示例时lib.rs
,我似乎无法导入bignum::inits::Zero
//lib.rs
//...
impl BigNum {
//...
/// Constructs a ...
///
/// # Examples
///
/// ```
/// extern crate bignum;
/// use bignum::inits::Zero;
///
/// let a = bignum::BigNum::new(Zero::zero());
/// ```
///
pub fn new(base: BigNum) -> BigNum {
// ...
}
当我运行时cargo test
,我收到此错误
Running target/debug/lib-fe3dd7a75a504b04
running 3 tests
test crate_from_u32 ... ok
test create_from_string ... ok
test adding_no_carry ... ok
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured
Doc-tests bignum
running 1 test
test new_0 ... FAILED
failures:
---- new_0 stdout ----
<anon>:3:9: 3:15 error: unresolved import `self::bignum::inits::Zero`. Did you mean `self::self::bignum::inits`?
<anon>:3 use self::bignum::inits::Zero;
^~~~~~
error: aborting due to previous error
thread 'new_0' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:192
failures:
new_0
我已经看到了这个问题,但这涉及从仍然需要顶级范围的同一文件中导入模块。但是在这里我仍然用bignum::
.
因此,虽然导入bignum::inits::Zero
适用于我的所有测试和示例,但它不适用于我的文档。这是为什么?我尝试self::
在前面追加并收到相同的错误。如果我将文档示例更改为
extern crate bignum;
let a = bignum::BigNum::new(bignum::inits::Zero::zero());
但是它编译得很好。如何正确导入我的模块?