I'm having difficulty fixing an error inside my documentation example for my library. I have the file structure like for my crate bignum
.
|-- Cargo.lock
|-- Cargo.toml
|-- examples
| |-- dat
| | `-- euler_13.dat
| |-- debug.rs
| `-- euler_13.rs
|-- README.md
|-- src
| |-- error.rs
| |-- inits.rs
| `-- lib.rs
In my examples, my headers will look something like
// euler_13.rs
extern crate bignum;
use bignum::inits::Zero;
// ...
This compiles and works great, but now when I'm writing an example inside my documentation at lib.rs
, I can't seem to import 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 {
// ...
}
When I run cargo test
, I receive this error
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
I've seen this question, but this deals with importing modules from the same file which still require toplevel scope. However here i'm still specifying top level scope with bignum::
.
So while importing bignum::inits::Zero
works for all of my tests and examples, it doesn't work for my docs. Why is that? I've tried appending self::
in front and receive the same error. If i change the doc examples to
extern crate bignum;
let a = bignum::BigNum::new(bignum::inits::Zero::zero());
it compiles fine however. How can I correctly import my modules?
# Examples
,extern create bignum
is implicit, so doing so again will create errors. I submitted an issue with a recommendation on changing the error output for this type of error – Auxochrome