How to use import in Rust doc?

I Have a simple library project in Rust.

The structure

The root's :

mod account_library;
mod error_handler;
mod record_library;

pub use account_library::*;
pub use error_handler::*;
pub use record_library::*;

the /account_library/

/// Very simple struct about an enum.
/// How to use:
/// ```
/// # use crate::account_library::AccountSide;
/// let side = AccountSide::Debet;
/// ```
#[derive(Deserialize, Serialize)]
pub enum AccountSide {

The problem is whenever I run the cargo test command, the rust compiler can't find the AccountSide Enum that I declared just right below the comment. It's in the same file.

error[E0432]: unresolved import `crate::account_library`
 --> src\account_library\
3 | use crate::account_library::AccountSide;
  |            ^^^^^^^^^^^^^^^ could not find `account_library` in the crate root

Here's what I've tried so far:

/// # use crate::AccountSide;  <---- no `AccountSide` in the root
/// # use AccountSide;         <---- no external crate `AccountSide`

Removing the # use also doesn't work

So what's wrong here ? and how to make this enum or any struct available inside the doc?

Doctests are compiled treating your crate as a dependency, not as part of the crate itself. So you should use book_keeper::account_library::AccountSide, as if you're the binary which pulled this crate via Cargo.toml.

Thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.