无法在 sub 子模块的范围内使用 mongodb crate 中的 `doc!` 宏

Cannot use the `doc!` macro from the mongodb crate in the scope of a sub sub module

我使用以下文件结构:

├── src
│   ├── main.rs     // Macros from here
│   ├── models
│   │   ├── mod.rs  // Loads the user.rs file
│   │   └── user.rs // Should be visible here
├── Cargo.toml

我的 main.rs 文件导入如下内容:

#[macro_use]
extern crate mongodb;

mod models;

我的 user.rs 文件如下所示:

pub struct User {
    username: String,
    password: String,
}

impl User {
    fn create_doc() {
        // Some code, but doc! from crate mongodb is not in this scope.
    }
}

如何在 user.rs 文件中使用我的 doc! 宏?我还尝试将 #[macro_use] 添加到 mod models; 之类的内容中,但没有任何效果。

mongodb crate(版本 0.3.1)has no such macro. The bson crate (version 0.9.0),mongodb 的依赖项,确实如此。您需要声明并从那里导入:

#[macro_use]
extern crate bson;
extern crate mongodb;

mongodb crate(版本 1.1.1)重新导出 bson。 在 Rust 2018 中你可以写

use mongodb::bson::doc